summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBill Wendling <wendling@ncsa.uiuc.edu>2001-02-22 22:01:58 (GMT)
committerBill Wendling <wendling@ncsa.uiuc.edu>2001-02-22 22:01:58 (GMT)
commit627a039fdbd3c6d782606f68ecee8e5262808699 (patch)
tree2d9ed5b0494c6a0730e7e7658d44b355b6f7edf2 /tools
parent55998df9edbfacb0e2b0a1907e66fa819fcec09f (diff)
downloadhdf5-627a039fdbd3c6d782606f68ecee8e5262808699.zip
hdf5-627a039fdbd3c6d782606f68ecee8e5262808699.tar.gz
hdf5-627a039fdbd3c6d782606f68ecee8e5262808699.tar.bz2
[svn-r3492] Purpose:
Code Movement Description: Moved these files to subdirectories in the tools/ directory. Platforms tested: Linux, Kelgia
Diffstat (limited to 'tools')
-rw-r--r--tools/Dependencies336
-rw-r--r--tools/h4toh5anno.c665
-rw-r--r--tools/h4toh5image.c861
-rw-r--r--tools/h4toh5main.c1629
-rw-r--r--tools/h4toh5main.h109
-rw-r--r--tools/h4toh5pal.c202
-rw-r--r--tools/h4toh5sds.c1096
-rw-r--r--tools/h4toh5test.c3944
-rw-r--r--tools/h4toh5util.c1633
-rw-r--r--tools/h4toh5util.h232
-rw-r--r--tools/h4toh5vdata.c831
-rw-r--r--tools/h4toh5vgroup.c812
-rw-r--r--tools/h5debug.c185
-rw-r--r--tools/h5dump.c4550
-rw-r--r--tools/h5dump.h17
-rw-r--r--tools/h5dumptst.c2577
-rw-r--r--tools/h5import.c141
-rw-r--r--tools/h5ls.c2166
-rw-r--r--tools/h5repart.c418
-rw-r--r--tools/h5toh4.c2592
-rw-r--r--tools/h5toh4.h43
-rw-r--r--tools/h5tools.c2688
-rw-r--r--tools/h5tools.h515
-rw-r--r--tools/pdb2hdf.c503
-rwxr-xr-xtools/testh4toh5.sh246
-rwxr-xr-xtools/testh5dump.sh197
-rwxr-xr-xtools/testh5ls.sh142
-rwxr-xr-xtools/testh5toh4.sh301
28 files changed, 0 insertions, 29631 deletions
diff --git a/tools/Dependencies b/tools/Dependencies
index e570192..e69de29 100644
--- a/tools/Dependencies
+++ b/tools/Dependencies
@@ -1,336 +0,0 @@
-## This file is machine generated on GNU systems.
-## Only temporary changes may be made here.
-
-h5tools.lo: \
- $(srcdir)/h5tools.c \
- $(srcdir)/h5tools.h \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h \
- $(top_srcdir)/src/H5private.h \
- $(top_builddir)/src/H5config.h \
- $(srcdir)/h5dump.h
-h5debug.lo: \
- $(srcdir)/h5debug.c \
- $(top_srcdir)/src/H5private.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_builddir)/src/H5config.h \
- $(top_srcdir)/src/H5Iprivate.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Bprivate.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Fprivate.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5ACprivate.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Pprivate.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Dprivate.h \
- $(top_srcdir)/src/H5Gprivate.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5Oprivate.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5HGprivate.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5Tprivate.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5Rprivate.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Sprivate.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Zprivate.h \
- $(top_srcdir)/src/H5HLprivate.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5FDfamily.h
-h5import.lo: \
- $(srcdir)/h5import.c \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h
-h5ls.lo: \
- $(srcdir)/h5ls.c \
- $(top_srcdir)/src/H5private.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_builddir)/src/H5config.h \
- $(srcdir)/h5tools.h \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h
-h5repart.lo: \
- $(srcdir)/h5repart.c \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h
-h5dump.lo: \
- $(srcdir)/h5dump.c \
- $(srcdir)/h5dump.h \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h \
- $(top_srcdir)/src/H5private.h \
- $(top_builddir)/src/H5config.h \
- $(srcdir)/h5tools.h
-h5toh4.lo: \
- $(srcdir)/h5toh4.c \
- $(srcdir)/h5toh4.h \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h \
- $(srcdir)/h5tools.h
-h5dumptst.lo: \
- $(srcdir)/h5dumptst.c \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h \
- $(top_srcdir)/src/H5private.h \
- $(top_builddir)/src/H5config.h
-pdb2hdf.lo: \
- $(srcdir)/pdb2hdf.c \
- $(top_srcdir)/src/hdf5.h \
- $(top_srcdir)/src/H5public.h \
- $(top_builddir)/src/H5pubconf.h \
- $(top_srcdir)/src/H5api_adpt.h \
- $(top_srcdir)/src/H5Ipublic.h \
- $(top_srcdir)/src/H5Apublic.h \
- $(top_srcdir)/src/H5ACpublic.h \
- $(top_srcdir)/src/H5Bpublic.h \
- $(top_srcdir)/src/H5Dpublic.h \
- $(top_srcdir)/src/H5Epublic.h \
- $(top_srcdir)/src/H5Fpublic.h \
- $(top_srcdir)/src/H5FDpublic.h \
- $(top_srcdir)/src/H5Gpublic.h \
- $(top_srcdir)/src/H5HGpublic.h \
- $(top_srcdir)/src/H5HLpublic.h \
- $(top_srcdir)/src/H5MMpublic.h \
- $(top_srcdir)/src/H5Opublic.h \
- $(top_srcdir)/src/H5Ppublic.h \
- $(top_srcdir)/src/H5Zpublic.h \
- $(top_srcdir)/src/H5Rpublic.h \
- $(top_srcdir)/src/H5Spublic.h \
- $(top_srcdir)/src/H5Tpublic.h \
- $(top_srcdir)/src/H5FDcore.h \
- $(top_srcdir)/src/H5FDfamily.h \
- $(top_srcdir)/src/H5FDmpio.h \
- $(top_srcdir)/src/H5FDsec2.h \
- $(top_srcdir)/src/H5FDstdio.h \
- $(top_srcdir)/src/H5FDsrb.h \
- $(top_srcdir)/src/H5FDgass.h \
- $(top_srcdir)/src/H5FDdpss.h \
- $(top_srcdir)/src/H5FDstream.h \
- $(top_srcdir)/src/H5FDmulti.h \
- $(top_srcdir)/src/H5FDlog.h
diff --git a/tools/h4toh5anno.c b/tools/h4toh5anno.c
deleted file mode 100644
index cd09e26..0000000
--- a/tools/h4toh5anno.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-converting an hdf4 annotation into an hdf5 attribute of the corresponding object.
-
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-#include "h4toh5main.h"
-
-
-/*-------------------------------------------------------------------------
- * Function: Annofil_h4_to_h5
- *
- * Purpose: translate file annotation object into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: file identifier
- h5_group: hdf5 group id
-
- *-------------------------------------------------------------------------
- */
-
-int Annofil_h4_to_h5(int32 file_id,hid_t h5group){
-
- int32 an_id;
- int32 ann_id;
- int32 i;
-
- int32 ann_length;
-
- int32 n_file_label = 0;
- int32 n_file_desc = 0;
- int32 n_data_label = 0;
- int32 n_data_desc = 0;
-
- int32 istat;
-
- char* ann_buf;
- char anno_labelname[30];
- char anno_descname[30];
- char index_str[5];
-
- hid_t h5_sid;
- hid_t h5_aid;
- hid_t sh5str_type;
- hid_t sh5str1_type;
- hid_t ret;
-
- an_id = ANstart(file_id);
-
- if(an_id < 0) {
- printf("error in obtaining an_id. \n");
- return FAIL;
- }
-
- istat = ANfileinfo(an_id,&n_file_label,&n_file_desc,
- &n_data_label,&n_data_desc);
-
- if(istat == FAIL) {
- printf("error getting file information.\n");
- ANend(file_id);
- return FAIL;
- }
-
- for (i = 0; i < n_file_label; i++) {
-
- ann_id = ANselect(an_id,i,AN_FILE_LABEL);
- if(ann_id == FAIL) {
- printf("error in obtaining annotation id. \n");
- ANend(file_id);
- return FAIL;
- }
-
- ann_length = ANannlen(ann_id);
- if(ann_length == FAIL) {
- printf("error in obtaining annotation length. \n");
- ANend(file_id);
- ANendaccess(ann_id);
- return FAIL;
- }
-
- ann_buf = malloc((size_t)ann_length + 1);
- if(ann_buf == NULL) {
- printf("error in allocating memory. \n");
- return FAIL;
- }
- h4toh5_ZeroMemory(ann_buf,(ann_length+1)*sizeof(char));
- istat = ANreadann(ann_id,ann_buf,ann_length+1);
-
- if(istat==FAIL) {
- printf("fail to read file information. \n");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- h5_sid = H5Screate(H5S_SCALAR);
-
- if (h5_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4 FILE ANNOTATION. \n");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
- printf("error in making string at FILE lABEL ANNO. \n");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- if(conv_int_str(i,index_str)== FAIL) {
- printf("fail to convert integer into character format.\n");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- strcpy(anno_labelname,HDF4_FILE_LABEL);
- strcat(anno_labelname,"_");
- strcat(anno_labelname,index_str);
-
-
- h5_aid = H5Acreate(h5group,anno_labelname,sh5str_type,
- h5_sid,H5P_DEFAULT);
-
- if (h5_aid <0) {
- printf("failed to obtain attribute id for");
- printf(" File annotation. \n");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- ret = H5Awrite(h5_aid,sh5str_type,(void *)ann_buf);
-
- if (ret <0) {
- printf("failed to obtain attribute.\n ");
- ANend(file_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- ret = H5Sclose(h5_sid);
- ret = H5Aclose(h5_aid);
- free(ann_buf);
- ANendaccess(ann_id);
-
- }
-
- for (i = 0; i < n_file_desc; i++) {
-
- ann_id = ANselect(an_id,i,AN_FILE_DESC);
- if(ann_id == FAIL) {
- printf("error in obtaining annotation id. \n");
- ANend(an_id);
- return FAIL;
- }
-
- ann_length = ANannlen(ann_id);
-
- if(ann_length == FAIL) {
- printf("error in obtaining annotation length. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- return FAIL;
- }
-
- ann_buf = malloc((size_t)ann_length+1);
- if(ann_buf == NULL) {
- printf("error in allocating memory. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- return FAIL;
- }
- h4toh5_ZeroMemory(ann_buf,ann_length+1);
-
- istat = ANreadann(ann_id,ann_buf,ann_length+1);
-
- if(istat == FAIL) {
- printf("error reading file information. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- if ((sh5str1_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
- printf("error in making string at FILE DESC. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- if(conv_int_str(i,index_str)==FAIL) {
- printf("fail to convert integer into character format.\n");
- ANend(an_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- strcpy(anno_descname,HDF4_FILE_DESC);
- strcat(anno_descname,"_");
- strcat(anno_descname,index_str);
-
- h5_sid = H5Screate(H5S_SCALAR);
-
- if (h5_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4 FILE ANNOTATION. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- free(ann_buf);
- return FAIL;
- }
-
- h5_aid = H5Acreate(h5group,anno_descname,sh5str1_type,
- h5_sid,H5P_DEFAULT);
-
- if (h5_aid <0) {
-
- printf("failed to obtain attribute id for");
- printf(" File annotation. \n");
- ANend(an_id);
- ANendaccess(ann_id);
- H5Sclose(h5_sid);
- free(ann_buf);
- return FAIL;
- }
-
- ret = H5Awrite(h5_aid,sh5str1_type,(void *)ann_buf);
-
- if (ret <0) {
- printf("failed to obtain attribute.\n ");
- ANend(an_id);
- ANendaccess(ann_id);
- H5Sclose(h5_sid);
- H5Aclose(h5_aid);
- free(ann_buf);
- return FAIL;
- }
-
- ret = H5Sclose(h5_sid);
- ret = H5Aclose(h5_aid);
- free(ann_buf);
- ANendaccess(ann_id);
- }
- ANend(an_id);
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: Annoobj_h4_to_h5
- *
- * Purpose: translate annotation object into attribute of hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: file identifier
- obj_ref: object reference
- obj_tag: object tag
- h5group: hdf5 group
-
- *-------------------------------------------------------------------------
- */
-int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
- hid_t h5group){
-
- int32 an_id;
- int32 ann_id;
- int32 i;
- int32 status;
- int32 ann_length;
-
- int32 n_file_label =-1;
- int32 n_file_desc =-1;
- int32 n_data_label =-1;
- int32 n_data_desc =-1;
-
- int num_lab_anno;
- int num_des_anno;
- int32 istat;
- int32* des_anno_list=NULL;
- int32* lab_anno_list=NULL;
-
- char* ann_buf;
- char* ann_obj_name;
- char ann_labelname[30];
-
- char index_str[5];
-
- hid_t h5_sid;
- hid_t h5_aid;
- hid_t sh5str_type;
- hid_t ret;
-
- an_id = ANstart(file_id);
- if(an_id == FAIL) {
- printf("fail to start annotation interface.\n");
- return FAIL;
- }
-
- istat = ANfileinfo(an_id,&n_file_label,&n_file_desc,
- &n_data_label,&n_data_desc);
-
- if(istat == FAIL ) {
- printf("error getting file information.\n");
- ANend(an_id);
- return FAIL;
- }
-
- num_lab_anno = ANnumann(an_id,AN_DATA_LABEL,obj_tag,obj_ref);
- num_des_anno = ANnumann(an_id,AN_DATA_DESC,obj_tag,obj_ref);
-
- if (num_lab_anno == FAIL) {
- printf("error getting number of annotation data label.\n");
- ANend(an_id);
- return FAIL;
- }
-
- if (num_des_anno == FAIL) {
- printf("error getting number of annotation object label.\n");
- ANend(an_id);
- return FAIL;
- }
-
- if(num_lab_anno > 0) {
-
- for(i=0; i<num_lab_anno;i++) {
- ann_id = ANselect(an_id,i,AN_DATA_LABEL);
-
- if(ann_id == FAIL) {
- printf("error in obtaining annotation id.\n");
- ANend(an_id);
- return FAIL;
- }
-
- ann_length = ANannlen(ann_id);
- if(ann_length == FAIL) {
- printf("error in getting annotation length. \n");
- ANendaccess(ann_id);
- ANend(an_id);
- return FAIL;
- }
-
- ann_buf = malloc((size_t)ann_length+1);
- if(ann_buf == NULL) {
- printf("error in allocating annotation memory.\n");
- ANendaccess(ann_id);
- ANend(an_id);
- return FAIL;
- }
- h4toh5_ZeroMemory(ann_buf,(ann_length+1)*sizeof(char));
- status = ANreadann(ann_id,ann_buf,ann_length+1);
- if(status == FAIL) {
- printf("error in reading data.\n");
- ANendaccess(ann_id);
- ANend(an_id);
- free(ann_buf);
- return FAIL;
- }
-
- status = ANendaccess(ann_id);
-
- h5_sid = H5Screate(H5S_SCALAR);
-
- if (h5_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4 FILE ANNOTATION. \n");
- ANend(an_id);
- free(lab_anno_list);
- free(ann_buf);
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
- printf("error in making string at OBJ LABEL. \n");
- ANend(an_id);
- free(lab_anno_list);
- free(ann_buf);
- return FAIL;
- }
-
- if(conv_int_str(i,index_str)== FAIL) {
- printf("fail to convert annotation index into character format.\n");
- ANend(an_id);
- free(lab_anno_list);
- free(ann_buf);
- return FAIL;
- }
-
- /* obtain annotation object name. The name is defined based on object tag
- */
- ann_obj_name = trans_tag_name(obj_tag,AN_DATA_LABEL);
-
- if(ann_obj_name != NULL)
- strcpy(ann_labelname,ann_obj_name);
-
- strcat(ann_labelname,"_");
- strcat(ann_labelname,index_str);
-
- h5_aid = H5Acreate(h5group,ann_labelname,sh5str_type,
- h5_sid,H5P_DEFAULT);
-
- if (h5_aid <0) {
-
- printf("failed to obtain attribute id for");
- printf(" file annotation. \n");
- ANend(an_id);
- free(lab_anno_list);
- free(ann_buf);
- free(ann_obj_name);
- return FAIL;
- }
-
- ret = H5Awrite(h5_aid,sh5str_type,(void *)ann_buf);
-
- if (ret <0) {
- printf("failed to obtain attribute.\n ");
- ANend(an_id);
- free(lab_anno_list);
- free(ann_buf);
- free(ann_obj_name);
- return FAIL;
- }
-
- ret = H5Sclose(h5_sid);
- ret = H5Aclose(h5_aid);
- free(ann_obj_name);
- free(ann_buf);
- }
- }
-
- if(num_des_anno > 0) {
-
-
- for (i = 0; i< num_des_anno;i++) {
-
- ann_id = ANselect(an_id,i,AN_DATA_DESC);
- if(ann_id == FAIL) {
- printf("error in obtaining annotation id.\n");
- ANend(an_id);
- return FAIL;
- }
- ann_length = ANannlen(ann_id);
- if(ann_length == FAIL) {
- printf("error in getting annotation length. \n");
- ANendaccess(ann_id);
- ANend(an_id);
- return FAIL;
- }
-
- ann_buf = malloc((size_t)ann_length+1);
-
- if(ann_buf == NULL) {
- printf("error in allocating annotation memory.\n");
- ANendaccess(ann_id);
- ANend(an_id);
- return FAIL;
- }
-
- h4toh5_ZeroMemory(ann_buf,(ann_length+1)*sizeof(char));
- ANreadann(ann_id,ann_buf,ann_length+1);
-
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
- printf("error in making string at OBJECT DESC. \n");
- ANend(an_id);
- free(des_anno_list);
- free(ann_buf);
- return FAIL;
- }
-
- if(conv_int_str(i,index_str)== FAIL) {
- printf("fail to convert annotation index into character format.\n");
- ANend(an_id);
- free(ann_buf);
- free(des_anno_list);
- return FAIL;
- }
- ann_obj_name = trans_tag_name(obj_tag,AN_DATA_DESC);
- if(ann_obj_name == NULL) {
- printf("error in obtaining tag name. \n");
- ANend(an_id);
- free(ann_buf);
- free(des_anno_list);
- return FAIL;
- }
-
- strcpy(ann_labelname,ann_obj_name);
- strcat(ann_labelname,"_");
- strcat(ann_labelname,index_str);
-
- h5_sid = H5Screate(H5S_SCALAR);
-
- if (h5_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4 OBJECT ANNOTATION. \n");
- ANend(an_id);
- free(des_anno_list);
- free(ann_buf);
- free(ann_obj_name);
- return FAIL;
- }
-
- h5_aid = H5Acreate(h5group,ann_labelname,sh5str_type,
- h5_sid,H5P_DEFAULT);
-
- if (h5_aid <0) {
-
- ANend(an_id);
- free(ann_buf);
- free(des_anno_list);
- free(ann_obj_name);
- printf("failed to obtain attribute id for ");
- printf("File annotation. \n");
- return FAIL;
- }
-
- ret = H5Awrite(h5_aid,sh5str_type,(void *)ann_buf);
-
- if (ret <0) {
- printf("failed to obtain attribute.\n ");
- ANend(an_id);
- free(ann_buf);
- free(des_anno_list);
- free(ann_obj_name);
- return FAIL;
- }
- ret = H5Sclose(h5_sid);
- ret = H5Aclose(h5_aid);
- free(ann_obj_name);
-
- free(ann_buf);
- }
-
- }
- ANend(an_id);
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: trans_tag_name
- *
- * Purpose: in annotation routine,
- translate annotation object tag into corresponding HDF5 object
- name.
-
- *
- * Return: NULL if failed, HDF5 object name if successful.
- *
- * In :
- obj_tag: hdf4 object tag
- annot_type: hdf4 annotation type
-
- *-------------------------------------------------------------------------
- */
-char* trans_tag_name(int32 obj_tag,ann_type annot_type){
-
- char* obj_name;
-
- obj_name = malloc(strlen(HDF4_VGROUP_LABEL)+1);
-
- if(obj_name == NULL) {
- printf("error in obtaining tag name. \n");
- return NULL;
- }
-
- if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG || obj_tag == DFTAG_SD) {
-
- if(annot_type == AN_DATA_LABEL)
- strcpy(obj_name,HDF4_SDS_LABEL);
-
- else if(annot_type == AN_DATA_DESC)
- strcpy(obj_name,HDF4_SDS_DESC);
- else
- return NULL;
- }
-
- else if(obj_tag == DFTAG_RIG || obj_tag == DFTAG_RI || obj_tag == DFTAG_RI8)
- {
- if(annot_type == AN_DATA_LABEL)
- strcpy(obj_name,HDF4_IMAGE_LABEL);
- else if(annot_type == AN_DATA_DESC)
- strcpy(obj_name,HDF4_IMAGE_DESC);
- else
- return NULL;
- }
-
- else if(obj_tag == DFTAG_VG) {
- if(annot_type == AN_DATA_LABEL)
- strcpy(obj_name,HDF4_VGROUP_LABEL);
- else if(annot_type == AN_DATA_DESC)
- strcpy(obj_name,HDF4_VGROUP_DESC);
- else
- return NULL;
- }
-
- else if(obj_tag == DFTAG_VS || obj_tag == DFTAG_VH) {
- if(annot_type == AN_DATA_LABEL)
- strcpy(obj_name,HDF4_VDATA_LABEL);
- else if(annot_type == AN_DATA_DESC)
- strcpy(obj_name,HDF4_VDATA_DESC);
- else
- return NULL;
- }
-
- else if(obj_tag == DFTAG_LUT) {
- if(annot_type == AN_DATA_LABEL)
- strcpy(obj_name,HDF4_PAL_LABEL);
- else if(annot_type == AN_DATA_DESC)
- strcpy(obj_name,HDF4_PAL_DESC);
- else
- return NULL;
- }
- return obj_name;
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/h4toh5image.c b/tools/h4toh5image.c
deleted file mode 100644
index 8fbbdc0..0000000
--- a/tools/h4toh5image.c
+++ /dev/null
@@ -1,861 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-converting an hdf4 image object into an hdf5 dataset, for three component image, this object will be converted into an hdf5 dataset with compound data type.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-#include "h4toh5main.h"
-
-/*-------------------------------------------------------------------------
- * Function: Image_h4_to_h5
- *
- * Purpose: translate Image object into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- ri_id: RI identifier
- h5_group: hdf5 group id
- h5_palgroup: hdf5 palette group id
-
- *-------------------------------------------------------------------------
- */
-
-int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
-
- int32 istat;
- int32 ngrattrs;
- int32 ncomp;
- int check_gloattr;
- int32 start[2];
- int32 edges[2];
- int32 dimsizes[2];
- uint16 gr_ref;
- int32 image_dtype;
-
- int check_imagename;
- int i;
- char image_name[MAX_GR_NAME];
- char grlabel[MAX_GR_NAME];
- char image_class[MAX_GR_NAME];
- char* h5cimage_name;
- void* image_data;
- HDF_CHUNK_DEF c_def_out;
- int32 chunk_dims[2];
- int32 c_flags;
-
- /* define varibles for hdf5. */
-
- hid_t h5ty_id;
- hid_t h5memtype;
-
- hid_t h5_ctype;
- hid_t h5_cmemtype;
-
- hid_t h5d_sid;
- hid_t h5dset;
-
- size_t h4size;
- size_t h4memsize;
- hsize_t fielddim[1];
- hsize_t h5dims[2];
- herr_t ret;
- hid_t create_plist;
-
- /* zeroing out memory.*/
-
- h4toh5_ZeroMemory(image_name,MAX_GR_NAME);
- h4toh5_ZeroMemory(image_class,MAX_GR_NAME);
- h4toh5_ZeroMemory(grlabel,MAX_GR_NAME);
-
- /* Obtain information of the image.*/
-
- if(GRgetchunkinfo(ri_id,&c_def_out,&c_flags)==FAIL){
- printf("error in getting chunking information. \n");
- return FAIL;
- }
-
- istat = GRgetiminfo(ri_id, image_name, &ncomp, &image_dtype,
- NULL, dimsizes, &ngrattrs);
-
- if(istat == FAIL) {
- printf("Cannot obtain GR info. at Image routine.\n");
- return FAIL;
- }
-
- /* data type transferring from hdf4 to hdf5. */
- if(h4type_to_h5type(image_dtype,&h5memtype,&h4memsize,
- &h4size,&h5ty_id)== FAIL) {
- printf("failed to translate image datatype. \n");
- return FAIL;
- }
-
- /* check whether the datatype is string. */
- if (h5ty_id == H5T_STRING) {
- /* rechange string datatype into numerical datatype.*/
-
- if(h5string_to_int(image_dtype,&h5memtype,h4memsize,
- &h5ty_id)== FAIL) {
- printf("error in translating H5T_STRING to int.\n");
- return FAIL;
- }
- }
-
- start[0] = 0;
- start[1] = 0;
- edges[0] = dimsizes[0];
- edges[1] = dimsizes[1];
-
- image_data = malloc(h4memsize*dimsizes[0]*dimsizes[1]*ncomp);
-
- if(image_data == NULL) {
- printf("error in allocating memory for image data. \n");
- return FAIL;
- }
-
- istat = GRreadimage(ri_id, start, NULL, edges, (VOIDP)image_data);
-
- if (istat == FAIL) {
- printf("error in reading images.\n");
- free(image_data);
- return FAIL;
- }
-
- /* change the order of image dimension:
- due to the difference of hdf4 image specification and
- hdf5 image specification. */
-
-
-
- h5dims[0] = edges[1]-start[1];
- h5dims[1] = edges[0]-start[0];
-
- gr_ref = GRidtoref(ri_id);
- if(gr_ref == 0) {
- printf("error in obtaining gr reference number. \n");
- free(image_data);
- return FAIL;
- }
-
- /* obtaining absolute path of image name.*/
-
- check_imagename = -10;
- h5cimage_name = get_name(gr_ref,2*num_images,gr_hashtab,&check_imagename);
-
- if (h5cimage_name == NULL && check_imagename == 0 ) {
- printf("error,cannot find image name.\n");
- free(image_data);
- return FAIL;
- }
-
- if (h5cimage_name == NULL && check_imagename == -1) {
- printf("error,image name is not defined.\n");
- free(image_data);
- return FAIL;
- }
-
- if (h5cimage_name == NULL && check_imagename == -2) {
- printf("error,not enough memory for get_name. \n");
- free(image_data);
- return FAIL;
- }
-
- /**** check number of component of the image object,
- and transfer HDF4 object into HDF5 object. ****/
-
- if (ncomp <= 0) {
- printf("error in obtaining image component\n");
- free(image_data);
- free(h5cimage_name);
- return FAIL;
- }
-
- /* create property list. */
-
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
-
- if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
- || c_flags == (HDF_CHUNK | HDF_NBIT) ){
-
- chunk_dims[0] = c_def_out.chunk_lengths[0];
- chunk_dims[1] = c_def_out.chunk_lengths[1];
-
- if(H5Pset_chunk(create_plist, 2, (hsize_t *)chunk_dims)<0) {
- printf("failed to set up chunking information for ");
- printf("property list.\n");
- free(image_data);
- H5Pclose(create_plist);
- return FAIL;
- }
- }
- if (ncomp == 1) {
-
- h5d_sid = H5Screate_simple(2,h5dims,NULL);
-
- if(h5d_sid <0) {
- printf("error in creating space for dataset. \n");
- free(image_data);
- free(h5cimage_name);
- return FAIL;
- }
-
- h5dset = H5Dcreate(h5_group,h5cimage_name,h5ty_id,h5d_sid,create_plist);
-
- if(h5dset < 0) {
- printf("error in creating hdf5 dataset converted from images. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
- image_data)<0) {
- printf("error writing data for hdf5 dataset converted from images.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- }
-
- else { /* compound datatype. */
-
- h5_ctype = H5Tcreate(H5T_COMPOUND,ncomp*h4size);
- if (h5_ctype < 0) {
- printf("error in generating hdf5 compound data type. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- h5_cmemtype = H5Tcreate(H5T_COMPOUND,ncomp*h4memsize);
- if (h5_cmemtype < 0) {
- printf("error in generating hdf5 memory compound data type. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
-
- fielddim[0] = ncomp;
-
- {
- hid_t arr_type; /* Array datatype for inserting fields */
-
- /* Create array datatype */
- if((arr_type=H5Tarray_create(h5ty_id,1,fielddim,NULL))<0) {
- printf("error creating array datatype.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- ret = H5Tinsert(h5_ctype,"HDF4Image_data",0,arr_type);
- if(ret < 0) {
- printf("error in inserting array of compound datatype. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- /* Close array datatype */
- if(H5Tclose(arr_type)<0) {
- printf("error closing array datatype.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- /* Create array datatype */
- if((arr_type=H5Tarray_create(h5memtype,1,fielddim,NULL))<0) {
- printf("error creating array datatype.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- ret = H5Tinsert(h5_cmemtype,"HDF4Image_data",0,arr_type);
- if(ret < 0) {
- printf("error in inserting array of compound datatype at memory. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- /* Close array datatype */
- if(H5Tclose(arr_type)<0) {
- printf("error closing array datatype.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
- }
-
- h5d_sid = H5Screate_simple(2,h5dims,NULL);
- if(h5d_sid < 0) {
- printf("error in creating space. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- h5dset = H5Dcreate(h5_group,h5cimage_name,h5_ctype,h5d_sid,
- create_plist);
- if(h5dset < 0) {
- printf("error in creating dataset. \n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if (H5Dwrite(h5dset,h5_cmemtype,h5d_sid,h5d_sid,H5P_DEFAULT,
- (void *)image_data)<0) {
- printf("error writing data\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- return FAIL;
- }
- ret = H5Tclose(h5_ctype);
- if(ret < 0) {
- printf("error in closing h5_ctype. \n");
- }
- ret = H5Tclose(h5_cmemtype);
- if(ret <0) {
- printf("error in closing h5_cmemtype. \n");
- }
- }
-
-/* convert image annotation into attribute of image dataset.
- Since there is no routines to find the exact tag of image object,
- we will check three possible object tags of image objects, that is:
- DFTAG_RIG,DFTAG_RI,DFTAG_RI8. If the object tag of image object is
- falling out of this scope, we will not convert annotations into
- hdf5 attributes; it is user's responsibility to make sure object tags
- for image objects are only one of the above three tags.*/
-
- if(Annoobj_h4_to_h5(file_id,gr_ref,DFTAG_RIG,h5dset)== FAIL){
- printf("failed to convert image annotation into hdf5 attribute.\n");
- free(image_data);
- free(h5cimage_name);
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(Annoobj_h4_to_h5(file_id,gr_ref,DFTAG_RI,h5dset)== FAIL){
- printf("failed to convert image annotation into hdf5 attribute.\n");
- free(h5cimage_name);
- free(image_data);
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(Annoobj_h4_to_h5(file_id,gr_ref,DFTAG_RI8,h5dset)== FAIL){
- printf("failed to convert image annotation into hdf5 attribute.\n");
- free(h5cimage_name);
- free(image_data);
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
-
- /************************************/
- /* translate GR attributes into HDF5 dataset attribute.*/
-
- check_gloattr = 0;
- if(gr_tranattrs(ri_id,h5dset,ngrattrs,check_gloattr)==FAIL){
- printf(" cannot obtain attributes. \n");
- free(image_data);
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- /* deal with h5dset predefined and user-defined attributes.
- Obtain the name and data type and the total number of attributes.
- Data attribute at hdf4 is only one-dimensional array. */
-
- if (ncomp == 1 && h4size == 1)
- strcpy(grlabel,RAST8LABEL);
- else if(ncomp == 3 && h4size == 1)
- strcpy(grlabel,RAST24LABEL);
- else
- strcpy(grlabel,GRLABEL);
-
- strcpy(image_class,IM_CLASS);
-
- /* transfer hdf4 predefined attributes into hdf5 dataset.*/
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,grlabel)==FAIL){
- printf("error in getting hdf4 image type attribute \n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_NAME,image_name)==FAIL){
- printf("error in getting hdf4 image name attribute. \n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,HDF4_IMAGE_CLASS,image_class)==FAIL){
- printf("error in getting hdf4 image class attribute. \n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- gr_ref = GRidtoref(ri_id);
-
- if(gr_ref == 0) {
- printf("error in obtaining reference number of GR.\n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- if(h4_transnumattr(h5dset,HDF4_REF_NUM,gr_ref)==FAIL) {
- printf("error in getting hdf4 image number attribute.\n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- /* deal with palette. */
-
- if(gr_palette(file_id,ri_id,h5dset,h5_palgroup)== FAIL) {
- printf("error in translating palette into h5 dataset.\n");
- H5Pclose(create_plist);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- free(h5cimage_name);
- free(image_data);
- return FAIL;
- }
-
- ret = H5Pclose(create_plist);
- ret = H5Sclose(h5d_sid);
- ret = H5Dclose(h5dset);
- istat = GRendaccess(ri_id);
- free(image_data);
- free(h5cimage_name);
- return SUCCEED;
-}
-
-/**** palette routine. ****/
-/*-------------------------------------------------------------------------
- * Function: gr_palette
- *
- * Purpose: translate palette into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: HDF4 identifier
- ri: raster image id
- h5dset: hdf5 dataset
- h5_palgroup: hdf5 palette group
-
- Out:
- *-------------------------------------------------------------------------
- */
-
-int gr_palette(int32 file_id,int32 ri_id,hid_t h5dset,hid_t h5_palgroup) {
-
- int32 pal_id;
- uint16 pal_ref;
- char palref_str[MAXREF_LENGTH];
- char palg_name[MAX_GR_NAME];
- char image_index[MAX_GR_NAME];
- int check_pal;
- int check_palname;
- int pal_stat;
- char* h5pal_name=NULL;
-
-
- /* get palette id */
- pal_id = GRgetlutid(ri_id,0);
- if(pal_id == FAIL) {
- printf("error in obtaining palette id. \n");
- return FAIL;
- }
-
- pal_ref = GRluttoref(pal_id);
-
- if(pal_ref >0) {
-
- /* convert reference number into string format. */
- if(conv_int_str(pal_ref,palref_str)==FAIL) {
- printf("error in converting palette reference number into string.\n");
- return FAIL;
- }
-
- /* check whether this palette has been looked up already. */
- check_pal = lookup(pal_ref,PAL_HASHSIZE,pal_hashtab);
-
- if( check_pal < 0) {
- printf("error at looking up palette table. \n");
- return FAIL;
- }
-
- /* if check_pal equals to 1, this palette has already been
- converted into hdf5 dataset, just obtain the palette name.
- if check_pal equals to 0, we will do the converting. */
-
- if(check_pal == 1) {
-
- h5pal_name = get_name(pal_ref,PAL_HASHSIZE,pal_hashtab,
- &check_palname);
-
- if (h5pal_name == NULL && check_palname == 0 ) {
- printf("error,cannot find group\n");
- return FAIL;
- }
-
- if (h5pal_name == NULL && check_palname == -1 ) {
- printf("error,group name is not defined.\n");
- return FAIL;
- }
-
- }
-
- if(check_pal == 0) {
- /* do converting. */
- strcpy(palg_name,HDF4_PALG);
-
- /* obtain hdf5 dataset name converted from palette,
- no name for hdf4 palette.*/
- h5pal_name = get_obj_aboname(NULL,palref_str,palg_name,HDF4_PALETTE);
- if(h5pal_name == NULL) {
- printf("error in getting hdf5 palette name.\n");
- return FAIL;
- }
-
- if(set_name(pal_ref,PAL_HASHSIZE,pal_hashtab,h5pal_name)==FAIL) {
- printf("error in setting object name.\n");
- free(h5pal_name);
- return FAIL;
- }
-
- pal_stat = Palette_h4_to_h5(file_id,pal_id,h5_palgroup,h5pal_name);
-
- if(pal_stat == FAIL) {
- printf("error occurring in transferring palette into dataset. \n");
- free(h5pal_name);
- return FAIL;
- }
-
- }
-
- if(create_pal_objref(h5dset,h5_palgroup,h5pal_name)== FAIL) {
- printf("error in creating palette object reference.\n");
- free(h5pal_name);
- return FAIL;
- }
-
- if(h5pal_name != NULL) free(h5pal_name);
-
- strcpy(image_index,HDF4_IMAGE_INDEXED);
- if(h4_transpredattrs(h5dset,HDF4_IMAGE_SUBCLASS,image_index)== FAIL) {
- printf("failed to transfer hdf4 image indexed.\n");
- return FAIL;
- }
- }
- return SUCCEED;
-}
-/***** end of palette application. *****/
-/*-------------------------------------------------------------------------
- * Function: gr_tranattrs
- *
- * Purpose: translate attributes of Image object into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- sri_id: RI identifier
- sh5_dset: hdf5 dataset
- snum_grattrs: number of attribute
- check_gloflag: flag to check whether this attribute belongs
- to gr interface.
-
- Out:
- *-------------------------------------------------------------------------
- */
-int gr_tranattrs(int32 sri_id, hid_t sh5_dset,int snum_grattrs,
- int check_gloflag) {
-
- char sgratrr_name[2*MAX_NC_NAME];
- char grglo[MAX_NC_NAME];
- char* grrepattr_name;
- int32 count_sgradata;
- int32 sgr_atype;
- size_t sh4_amemsize;
- size_t sh4_asize;
-
- hid_t sh5a_sid;
- hid_t sh5a_id;
- hid_t sh5_atype;
- hid_t sh5_amemtype;
- hid_t sh5str_type;
- hid_t sh5str_memtype;
- hsize_t sh5dims[MAX_VAR_DIMS];
- void* sgr_adata;
- herr_t sret;
- int i;
-
-
- for (i =0;i <snum_grattrs;i++) {
-
- if (GRattrinfo(sri_id,i,sgratrr_name,&sgr_atype,&count_sgradata)==FAIL){
- printf("unable to obtain attribute information. \n");
- return FAIL;
- }
-
- /*convert datatype for attribute. */
-
- if(h4type_to_h5type(sgr_atype,&sh5_amemtype,&sh4_amemsize,
- &sh4_asize,&sh5_atype)==FAIL){
- printf("unable to do type transferring.\n");
- return FAIL;
- }
-
- sgr_adata = malloc(sh4_amemsize*count_sgradata);
-
- if(GRgetattr(sri_id,i,(VOIDP)sgr_adata)==FAIL){
- printf("unable to get GR attributes. \n");
- return FAIL;
- }
-
- /* if attribute doesn't have name, a default name is set. */
- if(sgratrr_name[0] == '\0') {
- grrepattr_name = trans_obj_name(DFTAG_RIG,i);
- strcpy(sgratrr_name,grrepattr_name);
- free(grrepattr_name);
- }
-
- /* if the sds attribute is a file attribute. */
- if(check_gloflag == 1){
- strcpy(grglo,GLOIMAGE);
- strcat(sgratrr_name,"_");
- strcat(sgratrr_name,grglo);
- }
- /* now do attribute-transferring.
- 1. deal with string data type
- 2. set attribute space.
- 3. get attribute name, set property list. */
-
- if (sh5_atype == H5T_STRING) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space for IMAGE. \n");
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(count_sgradata*sh4_asize,H5T_STR_SPACEPAD))<0){
- printf("error in making string for image attribute \n");
- return FAIL;
- }
-
- /* check this line later. */
- if ((sh5str_memtype = mkstr(count_sgradata*sh4_amemsize,
- H5T_STR_SPACEPAD))<0){
- printf("error in making memory string. \n");
- return FAIL;
- }
-
- sh5a_id = H5Acreate(sh5_dset,sgratrr_name,sh5str_type,sh5a_sid,
- H5P_DEFAULT);
- if (sh5a_id <0) {
- printf("failed to obtain attribute id for IMAGE. \n");
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)sgr_adata);
-
- if (sret <0) {
- printf("failed to obtain attribute of IMAGE.\n ");
- return FAIL;
- }
-
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
-
- else {
-
- if (count_sgradata == 1) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create space id. \n");
- return FAIL;
- }
- }
- else {
-
- sh5dims[0] = count_sgradata;
- sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space. \n");
- return FAIL;
- }
- }
-
- sh5a_id = H5Acreate(sh5_dset,sgratrr_name,sh5_atype,sh5a_sid,
- H5P_DEFAULT);
-
- if(sh5a_id <0) {
- printf("failed to obtain attribute id. \n");
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)sgr_adata);
-
- if(sret <0) {
- printf("failed to obtain attribute.\n ");
- return FAIL;
- }
- sret = H5Aclose(sh5a_id);
- sret = H5Sclose(sh5a_sid);
-
- }
-
- free(sgr_adata);
-
- }
-
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: create_pal_objref
- *
- * Purpose: create object reference for palette
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- h5dset: hdf5 dataset
- h5_palgroup: hdf5 palette group
- h5pal_name: hdf5 palette name
-
- Out:
- *-------------------------------------------------------------------------
- */
-
-int create_pal_objref(hid_t h5dset,hid_t h5_palgroup,char *h5pal_name){
-
- hobj_ref_t pal_refdat;
- hsize_t pal_refDims[1];
- hid_t pal_refSpace;
- hid_t pal_refType;
- hid_t attribID;
- herr_t ret;
-
- pal_refDims[0] = 1;
- pal_refSpace = H5Screate_simple(1,pal_refDims,NULL);
-
- if(pal_refSpace < 0) {
- printf("error in obtaining reference space. \n");
- return FAIL;
- }
-
- pal_refType = H5Tcopy(H5T_STD_REF_OBJ);
- if(pal_refType < 0) {
- printf("error in obtaining reference type. \n");
- H5Sclose(pal_refSpace);
- return FAIL;
- }
-
- ret = H5Rcreate(&pal_refdat,h5_palgroup,h5pal_name,
- H5R_OBJECT,-1);
- if(ret < 0) {
- printf("error in creating reference space. \n");
- H5Sclose(pal_refSpace);
- H5Tclose(pal_refType);
- return FAIL;
- }
-
- attribID = H5Acreate(h5dset,PALETTE,pal_refType,pal_refSpace,
- H5P_DEFAULT);
-
- if(attribID < 0) {
- printf("error in obtaining attribute ID. \n");
- H5Sclose(pal_refSpace);
- H5Tclose(pal_refType);
- return FAIL;
- }
-
- ret = H5Awrite(attribID,pal_refType,(void *)&pal_refdat);
-
-
- H5Sclose(pal_refSpace);
- if(H5Tclose(pal_refType)<0) {
- printf("error closing palette reference type.\n");
- H5Aclose(attribID);
- }
- H5Aclose(attribID);
- return SUCCEED;
-}
diff --git a/tools/h4toh5main.c b/tools/h4toh5main.c
deleted file mode 100644
index 5e7c6d6..0000000
--- a/tools/h4toh5main.c
+++ /dev/null
@@ -1,1629 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-This file describes the main driver of hdf to hdf5 converter. It checks
-the inputting parameters, initializes the global tables, sets up the root level
-hdf5 structure and also check the special case fof vgroup loops at HDF file.
-
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-
-#include "h4toh5main.h"
-
-int32 estnum_vg;
-int32 estnum_vd;
-int32 num_sds;
-int32 num_images;
-int num_objects;
-int32 num_glsdsattrs;
-int32 num_glgrattrs;
-struct table* sds_hashtab;
-struct table* gr_hashtab;
-struct table* vg_hashtab;
-struct table* vd_hashtab;
-struct table* pal_hashtab;
-struct name_table* name_hashtab;
-struct name_table* dim_hashtab;
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: driver routine to handle all objects of hdf4 file.
- *
- * Return: FAIL if failed, SUCCEED if successful.
-
- Modfication:
- *-------------------------------------------------------------------------
- */
-
-
-
-int main(int argc, char ** argv) {
-
- char *h5_filename=NULL;
- char *h4_filename=NULL;
- char *h5_extension;
- int status = 0;
-
- argc--;
- argv++;
-
- if (argc == 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h4toh5();
- return FAIL;
- }
-
- /* take care -h (help) option first */
- { int i;
- for (i=0; i < argc; i++)
- if ( HDstrcmp(argv[i],"-h") == 0 ) {
- PrintOptions_h4toh5();
- return SUCCEED;
- }
- }
-
-
- switch(argc) {
-
- case 0:
-
- PrintOptions_h4toh5();
- break;
-
- case 1: /* h4toh5 file1 */
- h4_filename = argv[0];
-#ifndef WIN32
- if (test_file(h4_filename,O_EXCL,292) != 0 ) {
- /* 292 Decimal - 0444 Octal, a+r */
- printf("the current hdf4 file name is not set properly.\n");
- status = -1;
- break;
- }
- if (test_dir(h4_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h4_filename);
- status = -1;
- break;
- }
-#endif
- /*0. check whether this file is an hdf file. */
-
- if(!Hishdf(h4_filename)){
- printf("error: not an hdf file. \n");
- printf("the file will not be converted. \n");
- status = -1;
- break;
- }
- h5_extension = HDstrdup("h5");
- h5_filename = BuildFilename(h4_filename,h5_extension);
- if (h5_filename == NULL) {
- printf("error in creating hdf5 file name.\n");
- status = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h5_filename,O_CREAT|O_EXCL,436) != 0) {
- /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- printf("permission of hdf5 file is not set properly.\n");
- status = -1;
- break;
- }
-#endif
- status = h4toh5(h4_filename, h5_filename);
-
- if ( status == FAIL ) {
- printf("error in converting %s into %s\n",h4_filename,h5_filename);
- break;
- }
- if (h5_filename != NULL) {
- HDfree(h5_filename);
- }
-
- break;
-
- case 2: /* h4toh5 file_in file_out */
-
- h4_filename = argv[0];
- h5_filename = argv[1];
-
-#ifndef WIN32
- if (test_file(h4_filename,O_EXCL,292) != 0 ) {
- /* 292 Decimal - 0444 Octal, a+r */
- printf("permission of hdf4 file is not set properly.\n");
- status = -1;
- break;
- }
-
- if (test_dir(h4_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h4_filename);
- status = -1;
- break;
- }
-
-#endif
- /*0. check whether this file is a hdf file. */
-
- if(!Hishdf(h4_filename)){
- printf("error: not an hdf file. \n");
- printf("the file will not be converted. \n");
- status = -1;
- break;
- }
-
-#ifndef WIN32
- if (test_file(h5_filename,O_CREAT|O_RDWR,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- printf("permission of hdf5 file is not set properly.\n");
- status = -1;
- break;
- }
-
- if (test_dir(h4_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h4_filename);
- status = -1;
- break;
- }
-
-#endif
- status = h4toh5(h4_filename, h5_filename);
- if ( status == FAIL ) {
- printf("error in converting %sinto %s\n",h4_filename,h5_filename);
- break;
- }
- break;
-
- default:
- break;
- }
-
- return status;
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5
- *
- * Purpose: This routine checks out arguments sent, makes sure that hdf4
- file is valid, makes sure filename for hdf5 file is correct,
- and then call h4toh5().
-
- *-------------------------------------------------------------------------
- */
-int h4toh5(char*filename4, char*filename5) {
-
- /* define variables for hdf4. */
- int32 istat ; /* hdf4 library routine return value. */
- int32 file_id;/* file identfier of hdf file.*/
- int32 sd_id;/* sd interface identifer*/
- int32 gr_id;/* gr interface identifer*/
- int check_glo;
-
- /* define variables for hdf5. */
- hid_t file5_id;/* hdf5 file identifier. */
- hid_t h5_root;/* new hdf5 root group identifier.*/
-
- hid_t h5_dimg;/* hdf5 dimensional scale group identifier. */
- hid_t h5_palg;/* hdf5 palette group identifier. */
-
- /*1. open the current hdf4 file. */
-
- file_id = Hopen(filename4, DFACC_READ, 0);
- if(file_id == FAIL) {
- printf("error: no such hdf4 files. \n");
- return FAIL;
- }
-
- /* open sd interface.*/
- sd_id = SDstart(filename4,DFACC_READ);
- if(sd_id == FAIL) {
- printf("error: cannot start SD interface. \n");
- Hclose(file_id);
- return FAIL;
- }
-
- /* open gr interface.*/
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("error in obtaining gr id. \n");
- SDend(sd_id);
- Hclose(file_id);
- return FAIL;
- }
-
- /* open V interface. */
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("error in starting V interface. \n");
- SDend(sd_id);
- GRend(gr_id);
- Hclose(file_id);
- return FAIL;
- }
-
- /* 2. obtain number of hdf4 objects(sds,image,vdata,vgroup,palette)
- in this hdf4 file. */
-
- if(get_numof_hdf4obj(filename4,file_id) == FAIL) {
- printf("error in obtaining number of hdf4 objects.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- return FAIL;
- }
-
- /* set up global hash tables for hdf4 objects. */
- if(set_hashtables() == FAIL){
- printf("error in setting hashtables. \n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- return FAIL;
- }
-
- /* create hdf5 file. */
- file5_id = H5Fcreate(filename5,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);
-
- if (file5_id < 0) {
- fprintf(stderr, "unable to create hdf5 file \n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /* Initialize hdf5 group interface. */
- h5_root = H5Gopen(file5_id,"/");
-
- if(h5_root < 0) {
- printf("error in opening hdf5 root group. \n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /**** build up helper groups(dimensional scale and palette) ****/
- if(set_helpgroups(h5_root,&h5_dimg,&h5_palg)==FAIL) {
- printf("error setting up dimensional scale and palette groups.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /* convert global sds attributes into global attributes under root group.*/
- check_glo = 1;
-
- if(sds_transattrs(sd_id, h5_root,num_glsdsattrs,check_glo)==FAIL) {
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
-
- /* convert global image attributes into global attributes under root group.*/
- check_glo = 1;
-
- if(gr_tranattrs(gr_id, h5_root,num_glgrattrs,check_glo)==FAIL) {
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /* convert all objects in lone vgroups into corresponding hdf5 objects. */
- if(h4toh5lonevgs(file_id,sd_id,h5_root,h5_dimg,h5_palg)== FAIL) {
- printf("error in translating lone vgroup into hdf5 objects.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
-/*convert all objects in group rings into corresponding hdf5 objects. */
- if(h4toh5vgrings(file_id,sd_id,h5_root,h5_dimg,h5_palg) == FAIL){
- printf("error in translating vgroup rings into hdf5 objects.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /*convert all independent lone vdata into corresponding hdf5 datasets with
- compound data type. */
- if(h4toh5lonevds(file_id,h5_root) == FAIL){
- printf("error in translating lone independent vdata into hdf5 objects.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /*** convert hdf file annotations into hdf5 attributes under the root.***/
- if(Annofil_h4_to_h5(file_id,h5_root) == FAIL) {
- printf("error in translating file annotations into root attributes.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /*** deal with untouched sds objects.convert them into hdf5 datasets under root group.***/
-
- if(h4toh5unvisitedsds(file_id,sd_id,h5_root,h5_dimg) == FAIL) {
- printf("error in converting unvisited sds objects into hdf5 file.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- /*** deal with untouched image objects. convert them into hdf5 datasets under root group. ***/
-
- if(h4toh5unvisitedimages(file_id,h5_root,h5_palg) == FAIL) {
- printf("error in converting unvisited image objects into hdf5 file.\n");
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- free_allhashmemory();
- return FAIL;
- }
-
- free_allhashmemory();
- SDend(sd_id);
- GRend(gr_id);
- Vend(file_id);
- Hclose(file_id);
- if(num_sds >0) H5Gclose(h5_dimg);
- if(num_images >0) H5Gclose(h5_palg);
- H5Gclose(h5_root);
- H5Fclose(file5_id);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: get_numof_hdf4obj
- *
- * Purpose: get number or estimated number of hdf4 objects
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf file identifier
- filename: hdf file name
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-int get_numof_hdf4obj(char*filename,int32 file_id) {
-
- int32 sd_id;/* sd interface identifer*/
- int32 gr_id;/* gr interface identifer*/
- int num_lonevd;/* number of lone vdata*/
- int num_lonevg;/* number of lone vgroup.*/
- int32 istat;
-
- estnum_vg = 0;
- estnum_vd = 0;
- num_sds = 0;
- num_images = 0;
- num_objects = 0;
-
- /* obtain number of sds and number of global sds attribute. */
-
- sd_id = SDstart(filename,DFACC_READ);
- if(sd_id == FAIL) {
- printf("error: cannot start SD interface. \n");
- return FAIL;
- }
-
- if(SDfileinfo(sd_id,&num_sds,&num_glsdsattrs) == FAIL) {
- printf("error in obtaining SDS information from the file.\n");
- return FAIL;
- }
-
- /* obtain number of images and number of global image attributes.*/
-
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("error in obtaining gr id. \n");
- return FAIL;
- }
-
- if(GRfileinfo(gr_id,&num_images,&num_glgrattrs) == FAIL) {
- printf("error in obtaining GR information from the file. \n");
- return FAIL;
- }
-
- /* obtain number of lone vgroup and lone vdata. */
-
- istat = Vstart(file_id);
- if (istat == FAIL) {
- fprintf(stderr, "unable to start hdf4 V interface.\n");
- return FAIL;
- }
-
- num_lonevd = VSlone(file_id,NULL,0);
- if(num_lonevd == FAIL) {
- printf("error in obtaining lone vdata number. \n");
- return FAIL;
- }
-
- num_lonevg = Vlone(file_id,NULL,0);
- if(num_lonevg == FAIL) {
- printf("error in obtaining lone vgroup number. \n");
- return FAIL;
- }
-
- /* intelligent guess of the total number of vgroups,total number of
- independent vdata. */
-
- estnum_vg = 6* num_lonevg;
- estnum_vd = 4* num_lonevd;
-
- /* set the size of name hashtable to num_objects. */
- num_objects = estnum_vg + estnum_vd + num_sds + num_images;
-
- return SUCCEED;
-}
-
-
-
-/*-------------------------------------------------------------------------
- * Function: set_helpgroups
- *
- * Purpose: get number or estimated number of hdf4 objects
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- h5root: hdf5 group identifier
- h5dimgptr: h5 dimensional group pointer
- h5palgptr: h5 palette group pointer
- Modification:
- *-------------------------------------------------------------------------
- */
-
-int set_helpgroups(hid_t h5root,hid_t* h5dimgptr,hid_t* h5palgptr){
-
- hid_t h5_dimg=(-1);/* hdf5 dimensional scale group identifier. */
- hid_t h5_palg;/* hdf5 palette group identifier. */
-
- /*1. dimensional scale group.*/
-
- if(num_sds > 0) {
- h5_dimg = H5Gcreate(h5root,HDF4_DIMG,0);
- if (h5_dimg <0) {
- printf("error in creating hdf5 dimensional scale group. \n");
- return FAIL;
- }
-
- *h5dimgptr = h5_dimg;
- }
-
- /*2. palette group.*/
-
- if(num_images >0) {
- h5_palg = H5Gcreate(h5root,HDF4_PALG,0);
- if(h5_palg <0) {
- printf("error in creating hdf5 palette group. \n");
- if(h5_dimg>0) H5Gclose(h5_dimg);
- return FAIL;
- }
-
- *h5palgptr = h5_palg;
- }
-
- return SUCCEED;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: set_hashtables
- *
- * Purpose: set up hashtables
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-int set_hashtables(void) {
-
- if(num_sds > 0) {
- sds_hashtab = malloc(sizeof(struct table)*2*num_sds);
- if(init_tab(2*num_sds,sds_hashtab)== FAIL){
- printf("cannot initialize sds hashing table. \n");
- return FAIL;
- }
- }
-
- if(num_images > 0) {
- gr_hashtab = malloc(sizeof(struct table)*2*num_images);
- if(init_tab(2*num_images,gr_hashtab) == FAIL){
- printf("cannot initialize image hashing table. \n");
- return FAIL;
- }
- }
-
- /*hashtable is made to be fixed for dimensional scale and palette.*/
-
- if(num_sds > 0) {
- dim_hashtab = malloc(sizeof(struct name_table)*DIM_HASHSIZE);
- if(init_nametab(DIM_HASHSIZE,dim_hashtab) == FAIL) {
- printf("can not initialize dimension hashing table.\n");
- return FAIL;
- }
- }
-
- /* initialize the palette table */
- if(num_images > 0){
- pal_hashtab = malloc(sizeof(struct table)*PAL_HASHSIZE);
- if(init_tab(PAL_HASHSIZE,pal_hashtab) == FAIL) {
- printf("can not initialize palette hashing table.\n");
- return FAIL;
- }
- }
-
- /* initialize the vgroup table */
- if(estnum_vg > 0) {
- vg_hashtab = malloc(sizeof(struct table)*estnum_vg);
- }
- else {
- estnum_vg = VG_DEFHASHSIZE;
- vg_hashtab = malloc(sizeof(struct table)*estnum_vg);
- }
- if(init_tab(estnum_vg,vg_hashtab) == FAIL) {
- printf("error in allocating memory for vgroup hashing table.\n");
- return FAIL;
- }
-
- /* initialize the vdata table.*/
- if(estnum_vd > 0) {
- vd_hashtab = malloc(sizeof(struct table)*estnum_vd);
- }
- else {
- estnum_vd = VD_DEFHASHSIZE;
- vd_hashtab = malloc(sizeof(struct table)*estnum_vd);
- }
-
- if(init_tab(estnum_vd,vd_hashtab)== FAIL) {
- printf("cannot initialize vdata hashing table.\n");
- return FAIL;
- }
-
- /* The name hashtable is only for dealing with name clashing,
- num_objects is the size of the hash table. */
-
- if(num_objects != 0){
- name_hashtab = malloc(sizeof(struct name_table)*num_objects);
- if(init_nametab(num_objects,name_hashtab)== FAIL) {
- printf("cannot initialize name hashing table. \n");
- return FAIL;
- }
- }
-
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5lonevgs
- *
- * Purpose: Recursively convert hdf4 objects in lone vgroups into
- corresponding hdf5 datasets
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In : file_id: hdf file id
- sd_id: hdf sd interface id
- h5group: hdf5 group id
- h5_dimg: hdf5 dimensional scale group id
- h5_palg: hdf5 palette group id
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg) {
-
- int32 vgroup_id;
- int num_lonevg; /* number of lone vgroup.*/
- int32 *ref_array;
- int32 istat;
- char vgroup_name[VGNAMELENMAX];
- char* cor_vgroupname;
- char vgroup_class[VGNAMELENMAX];
- char refstr[MAXREF_LENGTH];
- int check_vgroup;
- int check_tabst;
- int lone_vg_number;
- char *h5cgroup_name;
-
- istat = Vstart(file_id);
- if (istat == FAIL) {
- fprintf(stderr, "unable to start hdf4 V interface.\n");
- return FAIL;
- }
-
- num_lonevg = Vlone(file_id,NULL,0);
-
- if (num_lonevg == FAIL) {
- printf("error in obtaining lone vgroup number. \n");
- return FAIL;
- }
-
- /* obtain object reference array. */
-
- /* if no lone vgroup, quit from this function. */
- if(num_lonevg == 0)
- return SUCCEED;
-
- ref_array = (int32 *)malloc(sizeof(int32) *num_lonevg);
-
- if(ref_array == NULL) {
- printf("error in allocating memory for ref_array.\n");
- return FAIL;
- }
-
- num_lonevg = Vlone(file_id,ref_array,num_lonevg);
-
- /* walk through every lone group in the file */
-
- for(lone_vg_number = 0; lone_vg_number < num_lonevg;
- lone_vg_number++) {
-
- vgroup_id = Vattach(file_id,ref_array[lone_vg_number],"r");
-
- if(vgroup_id ==FAIL) {
- printf("error in attaching lone vgroup.\n");
- free(ref_array);
- return FAIL;
- }
-
- /*obtain group name and class name.*/
- h4toh5_ZeroMemory(vgroup_class,VGNAMELENMAX);
- istat = Vgetclass(vgroup_id,vgroup_class);
- if(istat == FAIL) {
- printf("error in getting vgroup class.\n");
- free(ref_array);
- Vdetach(vgroup_id);
- return FAIL;
- }
-
- h4toh5_ZeroMemory(vgroup_name,VGNAMELENMAX);
- istat = Vgetname(vgroup_id,vgroup_name);
- if(istat == FAIL ) {
- printf("error in getting vgroup name. \n");
- Vdetach(vgroup_id);
- free(ref_array);
- return FAIL;
- }
-
- /* check for CDF0.0 and RIG0.0, if yes
- don't go into this group.*/
-
- if(strcmp(vgroup_class,_HDF_CDF)==0) {
- Vdetach(vgroup_id);
- continue;
- }
- if(strcmp(vgroup_class,GR_NAME)==0) {
- Vdetach(vgroup_id);
- continue;
- }
-
- /* converting integer number into string format. */
- if(conv_int_str(ref_array[lone_vg_number],refstr) == FAIL) {
- printf("ref. is negative, error in converting\n");
- Vdetach(vgroup_id);
- free(ref_array);
- return FAIL;
- }
-
- /* checking whether vgroup name contains ORI_SLASH, changing into CHA_SLASH.*/
- cor_vgroupname = correct_name(vgroup_name);
- if(cor_vgroupname == NULL) {
- printf("error in generating corrected vgroup name. \n");
- Vdetach(vgroup_id);
- free(ref_array);
- return FAIL;
- }
-
- /* obtaining group name of the converted lone vgroup. In this call,
- we will deal with cases such as name clashing and no available vgroup
- name. */
-
- h5cgroup_name = get_obj_aboname(cor_vgroupname,refstr,NULL,HDF4_VGROUP);
-
- if(h5cgroup_name == NULL) {
- printf("error in getting group name.\n");
- Vdetach(vgroup_id);
- free(ref_array);
- free(cor_vgroupname);
- return FAIL;
- }
-
- /* free memory of corrected name. */
- free(cor_vgroupname);
-
- /* updating lookup table for vgroups.*/
-
- check_vgroup = lookup(ref_array[lone_vg_number],estnum_vg,vg_hashtab);
-
- if(check_vgroup == 0) { /* adding this vgroup into the list. */
-
- check_tabst = set_name(ref_array[lone_vg_number],estnum_vg,
- vg_hashtab,h5cgroup_name);
- if(check_tabst == FAIL) {
- printf("not enough memory to be allocated for vgroup name. \n");
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- free(ref_array);
- return FAIL;
- }
- }
-
- /* this line should never fail, if failed, something is wrong with converter or hdf library. */
-
- if(check_vgroup == 1){
- fprintf(stderr,"this vgroup should not be touched. \n");
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- free(ref_array);
- return FAIL;
- }
-
- if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg)==FAIL){
- printf("error in translating vgroup into hdf5 objects.\n");
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- free(ref_array);
- return FAIL;
- }
-
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- }
- free(ref_array);
- return SUCCEED;
-}
-
-
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5vgrings
- *
- * Purpose: Recursively convert objects at special hdf4 vgroups
- (vgroup rings)
- into objects of corresponding hdf5 groups. The strategy here
- is to arbitrily grab any vgroup in the group ring and put it
- under hdf5 root.
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In : file_id: hdf file id
- sd_id: hdf sds id
- h5group: hdf5 group id
- h5_dimg: hdf5 dimensional scale group id
- h5_palg: hdf5 palette group id
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-
-int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg){
-
- int32 vgroup_id;
- int32 ref_num;
- char vgroup_name[VGNAMELENMAX];
- char* cor_vgroupname;
- char vgroup_class[VGNAMELENMAX];
- char refstr[MAXREF_LENGTH];
- int check_vgroup;
- int32 istat;
- char *h5cgroup_name;
-
- ref_num = Vgetid(file_id,-1);
-
- while (ref_num != -1) {
-
- /* if we find a group that is not touched, grab it under root group.*/
-
- check_vgroup = lookup(ref_num,estnum_vg,vg_hashtab);
-
- if (check_vgroup == 0){
-
- vgroup_id = Vattach(file_id,ref_num,"r");
- if(vgroup_id ==FAIL) {
- printf("error in attaching group in a group ring. \n");
- return FAIL;
- }
-
- h4toh5_ZeroMemory(vgroup_name,VGNAMELENMAX);
- istat = Vgetname(vgroup_id,vgroup_name);
- if(istat ==FAIL) {
- printf("error in obtaining vgroup names. \n");
- Vdetach(vgroup_id);
- return FAIL;
- }
-
- h4toh5_ZeroMemory(vgroup_class,VGNAMELENMAX);
- if(Vgetclass(vgroup_id,vgroup_class) == FAIL) {
- printf("error in obtaining vgroup class name. \n");
- Vdetach(vgroup_id);
- return FAIL;
- }
-
- /* do nothing for those predefined attribute.*/
-
- if(vgroup_class[0] != '\0') {
-
- if(strcmp(vgroup_class,_HDF_ATTRIBUTE)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,_HDF_VARIABLE)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,_HDF_DIMENSION)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,_HDF_UDIMENSION)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,_HDF_CDF)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,GR_NAME)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
-
- if(strcmp(vgroup_class,RI_NAME)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
- }
-
- if(vgroup_name[0] != '\0') {
- if(strcmp(vgroup_name,GR_NAME)==0) {
- ref_num = Vgetid(file_id,ref_num);
- Vdetach(vgroup_id);
- continue;
- }
- }
-
- /* convert reference number into string format. */
- if(conv_int_str(ref_num,refstr) == FAIL) {
- printf("ref. is negative, error in converting\n");
- Vdetach(vgroup_id);
- return FAIL;
- }
-
- /* checking whether vgroup name contains ORI_SLASH, changing into CHA_SLASH.*/
- cor_vgroupname = correct_name(vgroup_name);
- if(cor_vgroupname == NULL) {
- printf("error in generating corrected vgroup name. \n");
- Vdetach(vgroup_id);
- return FAIL;
- }
- /* obtain the hdf5 group name. */
- h5cgroup_name = get_obj_aboname(cor_vgroupname,refstr,NULL,HDF4_VGROUP);
-
- if(h5cgroup_name == NULL) {
- printf("error in getting vgroup name.\n");
- Vdetach(vgroup_id);
- free(cor_vgroupname);
- return FAIL;
- }
-
- free(cor_vgroupname);
- if(set_name(ref_num,estnum_vg,vg_hashtab,h5cgroup_name)==FAIL) {
- printf("error in setting h5 group name.\n");
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- return FAIL;
- }
-
- if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg)
- ==FAIL){
-
- printf("error in translating vgroup into hdf5 group\n");
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- return FAIL;
- }
-
- Vdetach(vgroup_id);
- free(h5cgroup_name);
- }
- ref_num = Vgetid(file_id,ref_num);
- }
- return SUCCEED;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5lonevds
- *
- * Purpose: convert hdf4 lone vdata into
- the corresponding hdf5 datasets
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In : file_id: hdf file id
- h5group: hdf5 group id
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-int h4toh5lonevds(int32 file_id, hid_t h5group){
-
- int32 vdata_id;
- int32 *ref_vdata_array;
- int32 vdata_tag;
- int32 vdata_ref;
- int32 istat;
- char vdata_name[VGNAMELENMAX];
- char* cor_vdataname;
- char vdata_class[VGNAMELENMAX];
- char refstr[MAXREF_LENGTH];
- int check_vdata;
- int lone_vd_number;
- int num_lonevd;
- char *h5cvdata_name;
-
- num_lonevd = VSlone(file_id,NULL,0);
-
- if (num_lonevd == FAIL) {
- printf("error in obtaining lone vgroup number. \n");
- return FAIL;
- }
-
- if (num_lonevd > 0) {
-
- ref_vdata_array = (int32 *)malloc(sizeof(int32) *(num_lonevd));
-
- num_lonevd = VSlone(file_id,ref_vdata_array,num_lonevd);
-
- if(num_lonevd == FAIL) {
- printf("error in obtaining lone vdata number the second time.\n");
- free(ref_vdata_array);
- }
- /* walk through all lone vdatas. */
-
- for(lone_vd_number = 0; lone_vd_number < num_lonevd;lone_vd_number++)
- {
- vdata_id = VSattach(file_id,ref_vdata_array[lone_vd_number],"r");
-
- if(vdata_id == FAIL) {
- printf("error in obtaining vdata id for lone vdata.\n");
- free(ref_vdata_array);
- }
-
- /* Make sure this vdata is not an attribute of other hdf4 objects.*/
-
- if(!VSisattr(vdata_id)) {
-
- h4toh5_ZeroMemory(vdata_class,VGNAMELENMAX);
- istat = VSgetclass(vdata_id,vdata_class);
- if(istat == FAIL) {
- printf("error in getting vdata class name.\n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
-
-
- if(!strncmp(vdata_class,_HDF_CHK_TBL_CLASS,strlen(_HDF_CHK_TBL_CLASS))){
-
- VSdetach(vdata_id);
- continue;
- }
-
- vdata_ref = VSQueryref(vdata_id);
-
- if(vdata_ref == FAIL) {
- printf("error in getting vdata reference number.\n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
-
- vdata_tag = VSQuerytag(vdata_id);
- if(vdata_tag == FAIL){
- printf("error in getting vdata tag.\n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
-
-
- h4toh5_ZeroMemory(vdata_name,VGNAMELENMAX);
- istat = VSQueryname(vdata_id,vdata_name);
-
- if(istat == FAIL) {
- printf("error in getting vdata name. \n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
-
- /* converting reference number into string format.*/
- if(conv_int_str(ref_vdata_array[lone_vd_number],refstr)==FAIL) {
- printf("error in converting int to string.\n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
- /* checking whether vdata name contains ORI_SLASH, changing into CHA_SLASH.*/
- cor_vdataname = correct_name(vdata_name);
- if(cor_vdataname == NULL) {
- printf("error in generating corrected vgroup name. \n");
- VSdetach(vdata_id);
- free(ref_vdata_array);
- return FAIL;
- }
- /* obtaining hdf5 dataset name that is converted from hdf4 vdata.*/
- h5cvdata_name = get_obj_aboname(cor_vdataname,refstr,NULL,HDF4_VDATA);
- if(h5cvdata_name == NULL) {
- printf("error in getting vdata name.\n");
- free(ref_vdata_array);
- VSdetach(vdata_id);
- free(cor_vdataname);
- return FAIL;
- }
-
- free(cor_vdataname);
- check_vdata = lookup(ref_vdata_array[lone_vd_number],estnum_vd,
- vd_hashtab);
-
- /* check_vdata should be 1, if it is 1, either converter or hdf lib has bugs. */
- if(check_vdata == 1){
- printf("lone vdata should not be checked before.\n");
- free(h5cvdata_name);
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
-
- if(set_name(ref_vdata_array[lone_vd_number],estnum_vd,vd_hashtab,
- h5cvdata_name)==FAIL) {
- printf("error in setting lone vdata name. \n");
- free(ref_vdata_array);
- free(h5cvdata_name);
- VSdetach(vdata_id);
- return FAIL;
- }
-
- if(Vdata_h4_to_h5(file_id,vdata_id,h5group)== FAIL) {
- printf("error in translating independent vdata into");
- printf(" hdf5 datasets.\n");
- free(h5cvdata_name);
- free(ref_vdata_array);
- VSdetach(vdata_id);
- return FAIL;
- }
- free(h5cvdata_name);
- }
-
- VSdetach(vdata_id);
- }
- free(ref_vdata_array);
- }
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5unvisitedsds
- *
- * Purpose: convert unvisited sds objects into hdf5 datasets and put these
- datasets under hdf5 root group
- This routine will cover old hdf file that doesn't have vgroups.
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- sd_id: hdf sds id
- h5root: hdf5 root id
- h5_dimg: hdf5 dimensional scale group id
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-
-
-int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
-
- int i;
- int32 sds_id;/* sd dataset identifer*/
- int32 sds_rank;/* sds dataset dimension rank.*/
- int32 sds_dimsizes[DIM_HASHSIZE];/* array that contains the size of the each dimension in sds dataset.*/
- int32 sds_dtype;/*sds dataset datatype.*/
- int32 num_sdsattrs;/* number of sds attributes. */
- char sds_name[MAX_NC_NAME];/* sds name.*/
- char* cor_sdsname;
- int32 obj_ref; /* obj reference number assigned to sds and images.*/
- char refstr[MAXREF_LENGTH];/*object reference number in character string format.*/
- int check_sds;/* flag to check whether this sds is visited. 1 for visited and 0 for non-visited.*/
- char *h5csds_name;/* absolute path name of hdf5 dataset transferred from old sds.*/
-
- if(sd_id == FAIL) {
- printf("error: cannot start SD interface. \n");
- return FAIL;
- }
-
- /* check all sds objects. */
- for(i=0;i<num_sds;i++){
-
- sds_id = SDselect(sd_id,i);
-
- if (sds_id == FAIL) {
- printf("error in obtaining sd id.\n");
- return FAIL;
- }
-
- /* if this sds is dimensional scale, the converting should be ignored. dimensional scale will be converted separately. */
- if(SDiscoordvar(sds_id)) continue;
-
- /* obtain sds information. */
- if(SDgetinfo(sds_id,sds_name,&sds_rank,sds_dimsizes,
- &sds_dtype,&num_sdsattrs)== FAIL) {
- printf("error in obtaining SD info at ");
- printf("the unvisited sds routine.\n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- /* obtain object reference number of the current sds dataset.*/
- obj_ref = SDidtoref(sds_id);
- if(obj_ref == FAIL) {
- printf("error in obtaining sds object reference at ");
- printf("the unvisited sds routine.\n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- /* convert object reference number into string format. */
- if(conv_int_str(obj_ref,refstr) == FAIL) {
- printf("error in converting integer into string.\n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- /* check whether the current sds is visited or not. */
- check_sds = lookup(obj_ref,2*num_sds,sds_hashtab);
-
- /* if not visited, we will do the convertion. */
-
- if(check_sds == 0) {
- /* since different hdf sds may hold the same name and it is also
- legal that sds may not have a name; but for hdf5 dataset,
- it must hold a name, so we will use get_obj_aboname to assure
- that each new hdf5 dataset converted from
- sds objects will have a disabiguous name. */
-
- /* checking whether vgroup name contains ORI_SLASH, changing into CHA_SLASH.*/
- cor_sdsname = correct_name(sds_name);
- if(cor_sdsname == NULL) {
- printf("error in generating corrected sds name. \n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- h5csds_name = get_obj_aboname(cor_sdsname,refstr,NULL,HDF4_SDS);
- if(h5csds_name == NULL) {
- printf("error in obtaining sds name.\n");
- SDendaccess(sds_id);
- free(cor_sdsname);
- return FAIL;
- }
- free(cor_sdsname);
- /* put this name into hashtable. */
- if(set_name(obj_ref,2*num_sds,sds_hashtab,h5csds_name)==FAIL) {
- printf("error in setting object name.\n");
- SDendaccess(sds_id);
- free(h5csds_name);
- return FAIL;
- }
-
- /* do the convertion from sds into hdf5 dataset.*/
- if(Sds_h4_to_h5(file_id,sds_id,h5root,h5_dimg)== FAIL){
- printf("error in translating sds into hdf5 dataset.\n");
- SDendaccess(sds_id);
- free(h5csds_name);
- return FAIL;
- }
- free(h5csds_name);
-
- }
- SDendaccess(sds_id);
-
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h4toh5unvisitedimages
- *
- * Purpose: convert unvisited images into hdf5 dataset and put it
- under hdf5 root group
- This routine will cover old hdf file.
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf file id
- h5_root: hdf5 root id
- h5_palg: hdf5 palette group id
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-
-int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg) {
-
- int i;
- int32 istat;
- int32 gr_id;
- int32 ri_id;/*raster image identifer.*/
- char image_name[MAX_GR_NAME];/* image name.*/
- char* cor_imagename;
- int check_image;/* flag to check whether this image is visited. 1 for visited and 0 for non-visited.*/
- int32 obj_ref; /* obj reference number assigned to sds and images.*/
- char refstr[MAXREF_LENGTH];/*object reference number in character string format.*/
- char *h5cimage_name;/* absolute path name of hdf5 dataset transferred from old image.*/
-
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("error in obtaining gr id. \n");
- return FAIL;
- }
-
- /* check all images. */
- for (i=0;i<num_images;i++) {
-
- ri_id = GRselect(gr_id,i);
- if(ri_id ==FAIL) {
- printf("error in selecting gr interface.\n");
- return FAIL;
- }
-
- /* obtain information of GR */
- istat = GRgetiminfo(ri_id, image_name, NULL, NULL, NULL, NULL, NULL);
-
- if(istat == FAIL) {
- printf("error in getting GR images.\n");
- GRendaccess(ri_id);
- return FAIL;
- }
-
- /* obtain object reference number and convert it into string format. */
- obj_ref = GRidtoref(ri_id);
- if(obj_ref == 0) {
- printf("error in obtaining image reference number");
- printf(" at h4toh5unvisitedimages routine.\n");
- GRendaccess(ri_id);
- return FAIL;
- }
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("error in converting object reference number");
- printf(" into string at h4toh5unvisitedimages routine.\n");
- GRendaccess(ri_id);
- return FAIL;
- }
-
- /* check whether the current image is visited or not. */
- check_image = lookup(obj_ref,2*num_images,gr_hashtab);
-
- if(check_image == 0) {
-
- /* since different hdf image may hold the same name and it is
- also legal that an image may not have a name; but for hdf5
- dataset, it must hold a name, so we will use get_obj_aboname
- to guarrtte that each new hdf5 dataset converted from
- image objects will have a disabiguous name. */
-
- /* checking whether vgroup name contains ORI_SLASH,
- changing into CHA_SLASH.*/
-
- cor_imagename = correct_name(image_name);
- if(cor_imagename == NULL) {
- printf("error in generating corrected image name. \n");
- GRendaccess(ri_id);
- return FAIL;
- }
- h5cimage_name = get_obj_aboname(cor_imagename,refstr,NULL,
- HDF4_IMAGE);
- if(h5cimage_name == NULL) {
- printf("error in getting image name.\n");
- GRendaccess(ri_id);
- free(cor_imagename);
- return FAIL;
- }
- free(cor_imagename);
-
- if(set_name(obj_ref,2*num_images,gr_hashtab,h5cimage_name)==FAIL) {
- printf("error setting image name.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- return FAIL;
- }
-
- /* do the convertion from the image into hdf5 dataset.*/
- if(Image_h4_to_h5(file_id,ri_id,h5_root,h5_palg)== FAIL) {
- printf("error in transferring image name into hdf5 dataset.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- return FAIL;
- }
- free(h5cimage_name);
- }
- GRendaccess(ri_id);
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: free_allhashmemory()
- *
- * Purpose: free memory allocated for all hashtables
- *
- * Return:
- *
- * In :
-
-
- Out:
- Modification:
- *-------------------------------------------------------------------------
- */
-
-void free_allhashmemory(){
-
- if(estnum_vg != 0) freetable(estnum_vg,vg_hashtab);
- if(estnum_vd != 0) freetable(estnum_vd,vd_hashtab);
-
- if(num_sds !=0) {
- freetable(2*num_sds,sds_hashtab);
- freenametable(DIM_HASHSIZE,dim_hashtab);
- }
-
- if(num_images !=0) {
- freetable(2*num_images,gr_hashtab);
- freetable(PAL_HASHSIZE,pal_hashtab);
- }
-
- if(num_objects !=0) freenametable(num_objects,name_hashtab);
-
-}
-
-
-
-/********The following routines are adapted from h5toh4 converter. *******/
-/*****************************************************************************
-
- Routine: test_file
-
- Description: Test a file for read/write - ability.
-
- Input: filename - Unix filename
-
- Output: function return, global variable - errno
-
-*****************************************************************************/
-
-int test_file(char *filename,int oflag,mode_t mode)
-{
- int fid;
-
- errno = 0;
-
- fid = open(filename, oflag, mode);
- if (fid < 0) {
- perror(filename);
- }
- close(fid);
-
- return errno;
-
-}
-
-
-/*****************************************************************************
-
- Routine: test_dir
-
- Description: Test pathway to determine if it is a directory
-
- Input: path - pathname given
-
- Output: function return TRUE/FALSE
-
-*****************************************************************************/
-
-int test_dir(char *path)
-{
-
- struct stat buf;
- struct stat *buf_ptr;
- int idir;
-
- buf_ptr = &buf;
-
- idir = stat(path, buf_ptr);
- if (idir < 0) {
- if (errno == 2) {
- return 0;
- } else {
- perror(path);
- }
- }
-
- return S_ISDIR(buf_ptr->st_mode);
-}
-
-/*****************************************************************************
-
- Routine: BuildFilename()
-
- Description: Build a filename with new extension
-
- Input: filename - present filename
- ext - extension to root of filename
-
- Output: (filename:r).ext
-
-*****************************************************************************/
-
-char *BuildFilename(char *filename, char *ext)
-{
- /* build outgoing filename */
-
- char *filename_out;
- char *lastper_ptr, *lastdir_ptr;
- int root_len;
-
- lastper_ptr = strrchr(filename,'.');
- lastdir_ptr = strrchr(filename,'/');
-
- if ( lastper_ptr <= lastdir_ptr ) { /* no extension */
- root_len = strlen(filename);
- } else { /* existing extension */
- root_len = (int)(lastper_ptr - filename);
- }
-
- filename_out = (char *)HDmalloc(root_len + strlen(ext) + 2);
- filename_out = strncpy(filename_out, filename, (size_t)root_len);
- filename_out[root_len] = '\0';
- filename_out = strcat(filename_out,".");
- filename_out = strcat(filename_out,ext);
-
- return filename_out;
-}
-
-
-/*****************************************************************************
-
- Routine: PrintOptions_h4toh5()
-
- Description: This routine prints the acceptable argument formats out to stderr.
-
- Input: None
-
- Output: output to stderr
-
-*****************************************************************************/
-
-void PrintOptions_h4toh5(void)
-{
- fprintf(stderr,"\nUsage: ");
- fprintf(stderr,"\n h4toh5 -h (gives this print-out)\n");
- fprintf(stderr," h4toh5 input.hdf output.h5\n");
- fprintf(stderr," h4toh5 input.hdf\n");
-}
-
-
-
-
-
diff --git a/tools/h4toh5main.h b/tools/h4toh5main.h
deleted file mode 100644
index 2bb6c88..0000000
--- a/tools/h4toh5main.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
-Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-including declarations of subroutines of all .c files excluding h4toh5util.c.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-
-#ifndef H4TOH5MAIN_H
-#define H4TOH5MAIN_H
-#include "hdf.h"
-#include "mfhdf.h"
-#include "hdf5.h"
-#include "h4toh5util.h"
-#include <fcntl.h>
-#include <errno.h>
-#endif
-
-/* For windows support.*/
-#if WIN32
-typedef unsigned int mode_t;
-#endif
-
-#ifndef S_ISDIR
-#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR)
-#endif
-
-/* subroutines to check initial settings and inputting parameters.
-Adapted from h5toh4 tools and used for h4toh5main.c */
-
-void PrintOptions_h4toh5(void);
-int test_file(char *filename,int oflag,mode_t mode);
-int test_dir(char *);
-char *BuildFilename(char *filename, char *ext);
-
-/* subroutines for h4toh5main.c */
-int h4toh5(char*,char*);
-int get_numof_hdf4obj(char*,int32);
-int set_hashtables(void);
-int set_helpgroups(hid_t,hid_t*,hid_t*);
-int h4toh5lonevds(int32,hid_t);
-int h4toh5lonevgs(int32,int32,hid_t,hid_t,hid_t);
-int h4toh5vgrings(int32,int32,hid_t,hid_t,hid_t);
-int h4toh5unvisitedimages(int32,hid_t,hid_t);
-int h4toh5unvisitedsds(int32,int32,hid_t,hid_t);
-void free_allhashmemory(void);
-
-/*subroutines for h4toh5vgroup.c*/
-
-int Vgroup_h4_to_h5(int32,int32,int32,hid_t,hid_t,hid_t);
-int convert_vgroup(int32,int32, int32,char* ,hid_t,hid_t,hid_t);
-int convert_vdata(int32,int32,char*,hid_t);
-int convert_sds(int32,int32,int32,char*,hid_t,hid_t);
-int convert_image(int32,int32,char*,hid_t,hid_t);
-
-/*subroutines for h4toh5vdata.c*/
-
-int Vdata_h4_to_h5(int32,int32,hid_t);
-int vdata_transattrs(int32,hid_t,int,int,char*);
-int gen_h5comptype(int32,int32,size_t *,size_t*,hid_t*,hid_t*,hid_t,hid_t);
-
-/* subroutines for h4toh5sds.c*/
-int Sds_h4_to_h5(int32,int32,hid_t,hid_t);
-int sds_transattrs(int32, hid_t,int,int);
-int sdsdim_to_h5dataset(int32,int32,hid_t,hid_t,int32);
-
-
-/*subroutines for h4toh5image.c*/
-int Image_h4_to_h5(int32,int32,hid_t,hid_t);
-int gr_tranattrs(int32, hid_t,int,int);
-int gr_palette(int32,int32,hid_t,hid_t);
-int create_pal_objref(hid_t ,hid_t ,char *);
-
-/*subroutines for h4toh5anno.c*/
-char* trans_tag_name(int32,ann_type);
-int Annofil_h4_to_h5(int32,hid_t);
-int Annoobj_h4_to_h5(int32,int32,int32,hid_t);
-
-/*subroutines for h4toh5pal.c*/
-int Palette_h4_to_h5(int32,int32 ,hid_t,char *);
-
-
-
-
-
-
-
diff --git a/tools/h4toh5pal.c b/tools/h4toh5pal.c
deleted file mode 100644
index 556ecdc..0000000
--- a/tools/h4toh5pal.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-Converting an hdf4 palette object into a hdf5 dataset.
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-#include "h4toh5main.h"
-
-
-/*-------------------------------------------------------------------------
- * Function: Palette_h4_to_h5
- *
- * Purpose: translate palette into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: file id
- pal_id: PALETTE identifier
- h5_g: hdf5 group id
- pal_name: path name of the group where all palettes are in
-
- *-------------------------------------------------------------------------
- */
-
-int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
-
- int32 ncomp;
- int32 pal_ref;
- int32 pal_type;
- int32 interlace_mode;
- int32 num_entries;
- void* pal_data;
- size_t h4memsize;
- size_t h4size;
-
- char palette_label[MAX_PAL_NAME];
- char palette_class[MAX_PAL_NAME];
- char palette_type[MAX_PAL_NAME];
- char palette_colormodel[MAX_PAL_NAME];
-
- hid_t h5memtype;
- hid_t h5type;
- hid_t h5d_sid;
- hid_t h5dset;
- hsize_t h5dims[2];
-
- pal_ref = GRluttoref(pal_id);
-
- if(pal_ref <0) {
- printf("error in obtaining palette.\n");
- return FAIL;
- }
-
- /* no palette, just return. */
- if(pal_ref == 0) return SUCCEED;
-
- if(GRgetlutinfo(pal_id,&ncomp,&pal_type,&interlace_mode,&num_entries)==FAIL) {
- printf("error in getting palette information.\n");
- return FAIL;
- }
-
- if(h4type_to_h5type(pal_type,&h5memtype,&h4memsize,&h4size,&h5type)== FAIL) {
- fprintf(stderr,"failed to translate image datatype. \n");
- return FAIL;
- }
-
- /* according to mapping document, data type for palette will always be
- uint8. */
-
- if (h5type == H5T_STRING) {
- if(h5string_to_int(pal_type,&h5memtype,h4memsize,&h5type)==FAIL) {
- fprintf(stderr,"failed to translate H5T_STRING to int8.");
- return FAIL;
- }
- }
-
- h5dims[0] = num_entries;
- h5dims[1] = ncomp;
-
- pal_data = malloc(h4memsize*ncomp*num_entries);
-
- if (pal_data == NULL) {
- printf("error in allocating memory for palette data.\n");
- return FAIL;
- }
-
- if (GRreadlut(pal_id,(VOIDP)pal_data)==FAIL) {
- printf("error in reading palette data. \n");
- free(pal_data);
- return FAIL;
- }
-
- h5d_sid = H5Screate_simple(2,h5dims,NULL);
-
- if (h5d_sid <0) {
- printf("error in creating space.\n");
- free(pal_data);
- return FAIL;
- }
-
- h5dset = H5Dcreate(h5g,pal_name,h5type,h5d_sid,H5P_DEFAULT);
-
- if (h5dset < 0) {
- printf("error in creating dataset. \n");
- free(pal_data);
- H5Sclose(h5d_sid);
- return FAIL;
- }
-
- if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
- (void *)pal_data)<0) {
- fprintf(stdout,"error writing data for palette data\n");
- free(pal_data);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
- free(pal_data);
-
-
- strcpy(palette_label,PALABEL);
- strcpy(palette_class,PALETTE);
- strcpy(palette_type,PAL_TYPE);
- strcpy(palette_colormodel,RGB);
- /* convert palette annotation into attribute of palette dataset.
- Since there are no routines to find the exact tag of palette object,
- we will check three possible object tags of palette objects, that is:
- DFTAG_LUT. If the object tag of palette object is
- falling out of this scope, we will not convert annotations into
- hdf5 attributes; it is user's responsibility to make sure that object tags
- for palette objects are DFTAG_LUT.*/
-
- if(Annoobj_h4_to_h5(file_id,pal_ref,DFTAG_LUT,h5dset)== FAIL){
- printf("failed to convert palette annotation into hdf5 attribute.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,palette_label)==FAIL) {
- printf("unable to transfer palette label to HDF4 OBJECT TYPE.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,HDF4_PALETTE_CLASS,palette_class)==FAIL){
- printf("unable to transfer palette class to HDF4 PALETTE CLASS.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,HDF4_PALETTE_TYPE,palette_type)==FAIL){
- printf("unable to transfer palette type to HDF4 PALETTE TYPE.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
-
- if(h4_transpredattrs(h5dset,PAL_COLORMODEL,palette_colormodel)==FAIL){
- printf("unable to transfer palette type to HDF4 PALETTE TYPE.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
- if(h4_transnumattr(h5dset,HDF4_REF_NUM,pal_ref)==FAIL) {
- printf("unable to transfer palette reference number to HDF4 REF. NUM.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- return FAIL;
- }
- return SUCCEED;
-}
-
-
-
-
-
diff --git a/tools/h4toh5sds.c b/tools/h4toh5sds.c
deleted file mode 100644
index 89e5ddf..0000000
--- a/tools/h4toh5sds.c
+++ /dev/null
@@ -1,1096 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-Converting an hdf4 sds object into an hdf5 dataset.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-#include "h4toh5main.h"
-
-/*-------------------------------------------------------------------------
- * Function: Sds_h4_to_h5
- *
- * Purpose: translate SDS object into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- sds_id: SDS identifier
- h5_group: hdf5 group id
- h5_dimgroup: hdf5 dimension group id
- dim_pathname: dimensional path name
-
- *-------------------------------------------------------------------------
- */
-
-int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
-
- int32 sds_dtype;
- int32 sds_rank;
- int32 sds_dimsizes[MAX_VAR_DIMS];
- int32* sds_start;
- int32* sds_edge;
- int32* sds_stride;
- int32 count_sdsdata;
- int32 sds_ref;
- intn sds_empty;
- int32 istat;
- int i;
- int32 num_sdsattrs;
- void* sds_data;
-
- int check_sdsname;
- int check_gloattr;
-
- char sdsname[MAX_NC_NAME];
- char sdslabel[MAX_NC_NAME];
- size_t h4size;
- size_t h4memsize;
- HDF_CHUNK_DEF c_def_out;
- hsize_t* chunk_dims;
- int32 c_flags;
-
- /* define varibles for hdf5. */
-
- hid_t h5dset;
- hid_t h5d_sid;
- hid_t h5ty_id;
- hid_t h5_memtype;
- hid_t create_plist;
- hsize_t h5dims[MAX_VAR_DIMS];
- hsize_t max_h5dims[MAX_VAR_DIMS];
-
- char* h5csds_name;
-
- herr_t ret;
- /* zeroing out the memory for sdsname and sdslabel.*/
-
- h4toh5_ZeroMemory(sdsname,MAX_NC_NAME);
- h4toh5_ZeroMemory(sdslabel,MAX_NC_NAME);
- /* check whether the sds is empty. */
-
- if(SDcheckempty(sds_id,&sds_empty)== FAIL) {
- printf("error in running SDcheckempty routine. \n");
- return FAIL;
- }
-
- if(sds_empty != 0) return SUCCEED;
-
-
- /*check whether the sds is created with unlimited dimension. */
-
- if(SDgetchunkinfo(sds_id,&c_def_out, &c_flags)== FAIL) {
- printf("error in getting chunking information. \n");
- return FAIL;
- }
-
- /*obtain name,rank,dimsizes,datatype and num of attributes of sds */
- if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype,
- &num_sdsattrs)==FAIL) {
- printf("unable to get information of sds h5dset.\n");
- return FAIL;
- }
-
- /* obtain start,edge, stride and number of sds data. */
-
- sds_start = malloc(sizeof(int32)*sds_rank);
- if(sds_start == NULL) {
- printf("error in allocating memory for sds start.\n");
- return FAIL;
- }
-
- sds_edge = malloc(sizeof(int32)*sds_rank);
- if(sds_edge == NULL) {
- printf("error in allocating memory for sds edge.\n");
- free(sds_start);
- return FAIL;
- }
-
- sds_stride = malloc(sizeof(int32)*sds_rank);
- if(sds_stride == NULL) {
- printf("error in allocating memory for sds stride. \n");
- free(sds_start);
- free(sds_edge);
- return FAIL;
- }
-
- count_sdsdata = 1;
- for (i=0;i<sds_rank;i++){
- sds_stride[i] = 1;
- sds_start[i] = 0;
- sds_edge[i] = sds_dimsizes[i];
- count_sdsdata = count_sdsdata*sds_dimsizes[i];
-
- }
-
- for (i=0;i<sds_rank;i++) {
- h5dims[i] = sds_edge[i]-sds_start[i];
- max_h5dims[i] = h5dims[i];
- }
- if(SDisrecord(sds_id)) max_h5dims[0] = H5S_UNLIMITED;
-
- /* convert hdf4 data type to hdf5 data type. */
- if (h4type_to_h5type(sds_dtype,&h5_memtype,&h4memsize,&h4size,
- &h5ty_id) == FAIL) {
- printf("failed to translate datatype. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- return FAIL;
- }
-
- /* check whether the datatype is string, if we find string format,
- we will change them back into integer format.*/
-
- if (h5ty_id == H5T_STRING) {
- /* rechange string datatype into numerical datatype.*/
- if(h5string_to_int(sds_dtype,&h5_memtype,h4memsize,
- &h5ty_id)== FAIL) {
- printf("error in translating H5T_STRING to int.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- return FAIL;
- }
- }
-
- sds_data = malloc(h4memsize*count_sdsdata);
- if(sds_data == NULL) {
- printf("error in allocating memory. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- return FAIL;
- }
-
- istat = SDreaddata(sds_id, sds_start, sds_stride, sds_edge,
- (VOIDP)sds_data);
- if (istat == FAIL) {
- printf("unable to read data from h5dset. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- return FAIL;
- }
-
- /* obtaining reference number and name of h5 dataset
- corresponding to sds. */
-
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("error in obtaining sds reference number. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- return FAIL;
- }
-
- h5csds_name = get_name(sds_ref,2*num_sds,sds_hashtab,&check_sdsname);
- if (h5csds_name == NULL && check_sdsname == 0 ) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- printf("error,cannot find sds name \n");
- return FAIL;
- }
-
- if (h5csds_name == NULL && check_sdsname == -1) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- printf("error,sds name is not defined.\n");
- return FAIL;
- }
-
- if (h5csds_name == NULL && check_sdsname == -2) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- printf("error,not enough memory for allocating sds name.\n");
- return FAIL;
- }
-
- h5d_sid = H5Screate_simple(sds_rank,h5dims,max_h5dims);
-
- if (h5d_sid < 0) {
- printf("failed to create hdf5 data space converted from SDS. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- return FAIL;
- }
-
- /* create property list. */
-
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
- chunk_dims = malloc(sizeof(hsize_t)*sds_rank);
-
- /* if the sds is not chunked, but with unlimited dimension, we have to
- provide a chunk size for the corresponding hdf5 dataset. we will choose
- 1/2 dimension size right now. */
-
- if(c_flags == HDF_NONE && SDisrecord(sds_id))
- {
- for(i=0;i<sds_rank;i++){
- chunk_dims[i] = (hsize_t)(h5dims[i]/2);
- }
- if(H5Pset_chunk(create_plist, sds_rank, chunk_dims)<0) {
- printf("failed to set up chunking information for ");
- printf("property list.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- }
- if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
- || c_flags == (HDF_CHUNK | HDF_NBIT) ){
-
- for(i=0;i<sds_rank;i++)
- chunk_dims[i] = (hsize_t)c_def_out.chunk_lengths[i];
-
- if(H5Pset_chunk(create_plist, sds_rank, chunk_dims)<0) {
- printf("failed to set up chunking information for ");
- printf("property list.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
- }
-
-
- h5dset = H5Dcreate(h5_group,h5csds_name,h5ty_id,h5d_sid,create_plist);
-
- if (h5dset < 0) {
- printf("failed to create hdf5 dataset converted from SDS. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if (H5Dwrite(h5dset,h5_memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
- (void *)sds_data)<0) {
- printf("failed to write data into hdf5 dataset");
- printf(" converted from SDS.\n");
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- return FAIL;
- }
-
-
- /* convert sds annotation into attribute of sds dataset.
- Since there is no routines to find the exact tag of sds object,
- we will check three possible object tags of sds objects, that is:
- DFTAG_SD,DFTAG_SDG,DFTAG_NDG. If the object tag of sds object is
- falling out of this scope, we will not convert annotations into
- hdf5 attributes; it is user's responsibility to make sure object tags
- for sds objects are only one of the above three tags.*/
-
- if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_SD,h5dset)== FAIL){
- printf("failed to convert sds annotation into hdf5 attribute.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_SDG,h5dset)== FAIL){
- printf("failed to convert sds annotation into hdf5 attribute.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_NDG,h5dset)== FAIL){
- printf("failed to convert sds annotation into hdf5 attribute.\n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- /* convert sds dimensional scale dataset into hdf5 dataset. */
- if(sdsdim_to_h5dataset(sds_id,sds_rank,h5dset,h5_dimgroup,sds_dimsizes[0]) == FAIL) {
- printf("failed to convert dimensional scale to hdf5 dataset. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- return FAIL;
- }
- check_gloattr = 0;
- if (sds_transattrs(sds_id,h5dset,num_sdsattrs,check_gloattr)==FAIL) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- printf(" Error in obtaining sds attributes. \n");
- return FAIL;
- }
-
- /********************************************/
- /* handle extra attributes of sds : sds label, object type
- and reference num */
-
- strcpy(sdslabel,SDSLABEL);
-
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,sdslabel)==FAIL) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- printf("unable to transfer sds label to HDF4 OBJECT TYPE.\n");
- return FAIL;
- }
-
- if(sdsname[0] != '\0') {
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_NAME,sdsname)==FAIL){
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- printf("unable to transfer sds name to HDF5 dataset attribute.\n");
- return FAIL;
- }
- }
-
- if(h4_transnumattr(h5dset,HDF4_REF_NUM,sds_ref)==FAIL){
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- free(chunk_dims);
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- H5Pclose(create_plist);
- printf("unable to transfer sds ref. to HDF5 dataset attribute.\n");
- return FAIL;
- }
-
- istat = SDendaccess(sds_id);
- ret = H5Pclose(create_plist);
- ret = H5Sclose(h5d_sid);
- ret = H5Dclose(h5dset);
- free(sds_data);
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(chunk_dims);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: sds_transattrs
- *
- * Purpose: translate attribute of HDF4 SDS object into
- hdf5 dataset attribute
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- ssds_id: SDS identifier
- sh5_dset: hdf5 dataset
- snum_sdsattrs: number of sds attribute
- check_gloflag: a flag that check whether the attribute is
- a file attribute or a sds id or a dimensional scale id.
-
- *-------------------------------------------------------------------------
- */
-
-int sds_transattrs(int32 ssds_id, hid_t sh5_dset,int snum_sdsattrs,
- int check_gloflag) {
-
- char ssdsatrr_name[2*MAX_NC_NAME];
- char sdsglo[MAX_NC_NAME];
- char* sdsrepattr_name;
- int32 count_ssdsadata;
- int32 ssds_atype;
- size_t sh4_amemsize;
- size_t sh4_asize;
- hid_t sh5a_sid;
- hid_t sh5a_id;
- hid_t sh5_atype;
- hid_t sh5_amemtype;
- hid_t sh5str_type;
- hid_t sh5str_memtype;
- hsize_t sh5dims[MAX_VAR_DIMS];
- void* ssds_adata;
- herr_t sret;
- int i;
-
- for (i = 0;i < snum_sdsattrs; i++) {
-
- if (SDattrinfo(ssds_id,i,ssdsatrr_name,&ssds_atype,
- &count_ssdsadata)==FAIL){
- printf("unable to obtain SDS attribute information. \n");
- return FAIL;
- }
-
- /* make a table for the attribute type, to do the corresponding type. */
-
- if(h4type_to_h5type(ssds_atype,&sh5_amemtype,&sh4_amemsize,
- &sh4_asize,&sh5_atype)== FAIL) {
- printf("fail to translate sds attribute data type from H4 to H5. \n");
- return FAIL;
- }
-
- ssds_adata = malloc(sh4_amemsize * count_ssdsadata);
- if(ssds_adata == NULL) {
- printf("error, cannot allocate memory for sds attribute data. \n");
- return FAIL;
- }
-
- if(SDreadattr(ssds_id,i,(VOIDP)ssds_adata)== FAIL) {
- printf("error in reading attributes of sds object. \n");
- free(ssds_adata);
- return FAIL;
- }
-
- /* if attribute doesn't have name, a default name is set. */
- if(ssdsatrr_name[0] == '\0') {
- sdsrepattr_name = trans_obj_name(DFTAG_NDG,i);
- strcpy(ssdsatrr_name,sdsrepattr_name);
- free(sdsrepattr_name);
- }
-
- /* if the sds attribute is a file attribute. */
- if(check_gloflag == 1){
- strcpy(sdsglo,GLOSDS);
- strcat(ssdsatrr_name,"_");
- strcat(ssdsatrr_name,sdsglo);
- }
-
- /* now do attribute-transferring.
- 1. deal with string data type
- 2. set attribute space.
- 3. get attribute name, set property list. */
-
- if (sh5_atype == H5T_STRING) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- free(ssds_adata);
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(count_ssdsadata,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making string. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- /* check this line later. */
- if ((sh5str_memtype = mkstr(count_ssdsadata*sh4_amemsize,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making memory string. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5str_type,
- sh5a_sid,H5P_DEFAULT);
-
- if (sh5a_id <0) {
- printf("failed to obtain attribute id for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)ssds_adata);
-
- if (sret <0) {
- printf("failed to write attribute data for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- free(ssds_adata);
- return FAIL;
- }
-
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
-
- else {
-
- if(count_ssdsadata == 1) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
- if (sh5a_sid < 0) {
- printf("failed to create space id. \n");
- free(ssds_adata);
- return FAIL;
- }
- }
- else {
- sh5dims[0] = count_ssdsadata;
- sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space. \n");
- free(ssds_adata);
- return FAIL;
- }
- }
- sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5_atype,
- sh5a_sid,H5P_DEFAULT);
-
- if(sh5a_id <0) {
- printf("failed to obtain attribute id. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)ssds_adata);
-
- if(sret <0) {
- printf("failed to write attribute data.\n ");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- free(ssds_adata);
- return FAIL;
- }
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
- free(ssds_adata);
- }
- return SUCCEED;
-}
-/****************sdsdim_to_h5dataset*******************
-
- * Purpose: translate dimensional scale dataset into
- hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- sds_id: SDS identifier
- sds_rank: number of sds dimensions
- Out:
- Modification:
-
- *-------------------------------------------------------------------------
- */
-
-int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
- hid_t sh5_dimgroup,int32 firstdimsize) {
-
- int32 sdsdim_id;
- int32 sdsdim_type = 0;
- int32 sds_dimscasize[1];
- int32 istat;
- int i;
- int count_h5objref;/* this counter updates the number of h5 object reference. */
- int count_h5attrname;/*this counter updates the number of h5 dimensional name attribute.*/
-
- int check_gloattr;
- int32 num_sdsdimattrs;
- int check_sdsdim;
- void* dim_scadata;
-
- char sdsdim_name[MAX_NC_NAME+1];
- char* cor_sdsdimname;
- size_t h4dim_memsize;
- size_t h4dim_size;
-
- HDF_CHUNK_DEF c_def_out;
- int32 c_flags;
-
- /* define varibles for hdf5. */
-
- hid_t h5dim_dset;
- hid_t h5dim_sid;
-
- hid_t h5dim_tid;
- hid_t h5dim_memtype;
-
- hid_t h5dim_nameaid;
- hid_t h5dim_namesid;
-
- hid_t h5str_dimntype;
-
- hid_t attr_refSpace;
- hid_t attr_refType;
- hid_t attribID;
- hid_t create_plist;
-
- hsize_t h5dimscas[1];
- hsize_t max_h5dimscas[1];
- hsize_t h5dim_dims[1];
- hsize_t attr_refDims[1];
- hsize_t h5dim_chunkdim[1];
- hobj_ref_t dim_refdat;
-
- hobj_ref_t* alldim_refdat;
-
- char* h5sdsdim_name;
- char h5sdsdim_allname[MAX_VAR_DIMS * MAX_DIM_NAME];
- char h5newsdsdim_name[MAX_DIM_NAME];
- char h5dimpath_name[MAX_DIM_NAME];
- herr_t ret;
-
-
- /*zero out memory for h5sdsdim_allname and h5dimpath_name */
- h4toh5_ZeroMemory(h5sdsdim_allname,(MAX_VAR_DIMS*MAX_DIM_NAME)*sizeof(char));
- h4toh5_ZeroMemory(h5dimpath_name,MAX_DIM_NAME*sizeof(char));
-
- /*check whether the sds is created with unlimited dimension. */
-
- if(SDgetchunkinfo(sds_id,&c_def_out, &c_flags)== FAIL) {
- printf("error in getting chunking information. \n");
- return FAIL;
- }
-
- /* initialize the dimensional number of sds dimensions, h5dim_dims
- is used for grabbing hdf5 dimensional name list and object reference
- list. */
- h5dim_dims[0] = (hsize_t)sds_rank;
- count_h5objref = 0;
- count_h5attrname = 0;
-
- for (i = 0; i<sds_rank;i++) {
-
- sdsdim_id = SDgetdimid(sds_id,i);
-
- if(sdsdim_id == FAIL) {
- printf("error in obtaining sds dimension id. \n");
- return FAIL;
- }
-
- istat = SDdiminfo(sdsdim_id,sdsdim_name,sds_dimscasize,
- &sdsdim_type,&num_sdsdimattrs);
-
- if (istat == FAIL) {
- printf("sds get dim. information failed. \n");
- SDendaccess(sdsdim_id);
- return FAIL;
- }
-
- /* for unlimited sds dimension, grab the current dimensional size. */
- if(sds_dimscasize[0] == 0) sds_dimscasize[0] = firstdimsize;
-
- /* check whether this dimensional scale dataset is looked up. */
- check_sdsdim = lookup_name(sdsdim_name,DIM_HASHSIZE,dim_hashtab);
-
- strcpy(h5dimpath_name,HDF4_DIMG);
-
- /* checking whether sds dimension scale name contains ORI_SLASH, changing into CHA_SLASH.*/
-
- cor_sdsdimname = correct_name(sdsdim_name);
- if(cor_sdsdimname == NULL) {
- printf("error in generating corrected sds dimensional scale name.\n");
- SDendaccess(sdsdim_id);
- return FAIL;
- }
-
- /* generating hdf5 dimensional scale name. */
- h5sdsdim_name = get_obj_aboname(cor_sdsdimname,NULL,h5dimpath_name,NULL);
- if (h5sdsdim_name == NULL) {
- printf("error in getting hdf5 sds dimension name.\n");
- SDendaccess(sdsdim_id);
- free(cor_sdsdimname);
- return FAIL;
- }
- free(cor_sdsdimname);
-
- strcpy(&h5sdsdim_allname[count_h5attrname*MAX_DIM_NAME],h5sdsdim_name);
-
- /* here we should add some comments for fakedim0--name. It seems that
- hdf4(netcdf) will use unique fake dimension name, fakedim + unique
- number, so check_sdsdim will never be 1 if the dimension name is fake
- name. Under this case, count_h5objref and count_h5attrname
- will not increase if this dimension doesnot
- have dimensional scale data. That assures the object reference of sds is
- correct. */
-
- /*if this dimension is not touched, get name of the dimensional scale data. */
- if (check_sdsdim == 1){/* the dimension is touched, skip this one.*/
- free(h5sdsdim_name);
- SDendaccess(sdsdim_id);
- count_h5objref = count_h5objref + 1;
- count_h5attrname = count_h5attrname + 1;
- continue;
- }
-
- if (check_sdsdim != 0) {
- printf("error in checking sds dimensions.\n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- return FAIL;
- }
-
- /* if this sds dimension has no dimensional scale data. skip it.*/
- if(sdsdim_type == 0)
- continue;
-
-
- /* get h5 dimensional scale data type. */
- if(h4type_to_h5type(sdsdim_type,&h5dim_memtype,&h4dim_memsize,
- &h4dim_size,&h5dim_tid)== FAIL) {
- printf("error in transferring sds dimension data type.\n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- return FAIL;
- }
-
- /* dimensional scale dataset cannot be H5T_STRING data type.
- So transferring back to int8 */
-
- if (h5dim_tid == H5T_STRING) {
- if(h5string_to_int(sdsdim_type,&h5dim_memtype,h4dim_memsize,
- &h5dim_tid)==FAIL){
- printf("error in translating from string to int. \n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- return FAIL;
- }
- }
-
- /* get the dimensional scale data. */
- dim_scadata = malloc(h4dim_memsize*sds_dimscasize[0]);
- istat = SDgetdimscale(sdsdim_id,(VOIDP)dim_scadata);
-
- if (istat == FAIL) {
- printf("sds get dim. scale failed. \n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- free(dim_scadata);
- return FAIL;
- }
-
- /* set dimensional scale size properly. */
- h5dimscas[0] = sds_dimscasize[0];
-
- /* only set for the first dimension if SDS is unlimited dimension. */
- if(SDisrecord(sds_id) && i == 0)
- max_h5dimscas[0] = H5S_UNLIMITED;
- else
- max_h5dimscas[0] = h5dimscas[0];
-
- h5dim_sid = H5Screate_simple(1,h5dimscas,max_h5dimscas);
-
- if(h5dim_sid <0) {
- printf("error in creating space. \n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- free(dim_scadata);
- return FAIL;
- }
-
- /* create property list, for chunked sds or unlimited dimension cases */
-
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
-
- if(create_plist == -1) {
- printf("failed to create property list. \n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- free(dim_scadata);
- H5Sclose(h5dim_sid);
- }
-
-
- if(c_flags == HDF_NONE && SDisrecord(sds_id) && i == 0)
- {
- h5dim_chunkdim[0] = (hsize_t)(h5dimscas[0]/2);
-
- if(H5Pset_chunk(create_plist,1, h5dim_chunkdim)<0) {
- printf("failed to set up chunking information for ");
- printf("dimensional scale property list.\n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- free(dim_scadata);
- H5Sclose(h5dim_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- }
-
- if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
- || c_flags == (HDF_CHUNK | HDF_NBIT) ){
-
- h5dim_chunkdim[0] = (hsize_t)c_def_out.chunk_lengths[0];
-
- if(H5Pset_chunk(create_plist,1, h5dim_chunkdim)<0) {
- printf("failed to set up chunking information for ");
- printf("property list.\n");
- SDendaccess(sdsdim_id);
- free(h5sdsdim_name);
- free(dim_scadata);
- H5Sclose(h5dim_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
- }
-
- /* create h5 dataset under group HDF4_DIMG*/
- h5dim_dset = H5Dcreate(sh5_dimgroup,h5sdsdim_name,h5dim_tid,
- h5dim_sid,create_plist);
-
- if(h5dim_dset <0) {
- printf("error in creating dataset. \n");
- free(h5sdsdim_name);
- free(dim_scadata);
- SDendaccess(sdsdim_id);
- H5Sclose(h5dim_sid);
- H5Pclose(create_plist);
- return FAIL;
- }
-
- if (H5Dwrite(h5dim_dset,h5dim_memtype,h5dim_sid,h5dim_sid,
- H5P_DEFAULT,(void *)dim_scadata)<0) {
- printf("error writing data\n");
- free(h5sdsdim_name);
- free(dim_scadata);
- SDendaccess(sdsdim_id);
- H5Sclose(h5dim_sid);
- H5Pclose(create_plist);
- H5Dclose(h5dim_dset);
- return FAIL;
- }
-
- check_gloattr = 0;
- if(sds_transattrs(sdsdim_id,h5dim_dset,num_sdsdimattrs,check_gloattr)
- == FAIL){
- printf("error in transferring attributes. \n");
- free(h5sdsdim_name);
- free(dim_scadata);
- SDendaccess(sdsdim_id);
- H5Sclose(h5dim_sid);
- H5Dclose(h5dim_dset);
- H5Pclose(create_plist);
- return FAIL;
- }
- SDendaccess(sdsdim_id);
- free(dim_scadata);
- free(h5sdsdim_name);
- ret = H5Sclose(h5dim_sid);
- ret = H5Dclose(h5dim_dset);
- ret = H5Pclose(create_plist);
- count_h5objref = count_h5objref + 1;
- count_h5attrname =count_h5attrname + 1;
- }
-
- /*1. create object reference number to dimensional scale dataset.
- 2. store absolute name of dimensional name into
- dimensional list. */
-
- if ( count_h5objref != 0) {
-
- h5dim_dims[0] = count_h5objref;
- attr_refDims[0] = count_h5objref;
- attr_refSpace = H5Screate_simple(1,attr_refDims,NULL);
- attr_refType = H5Tcopy(H5T_STD_REF_OBJ);
- alldim_refdat = calloc((size_t)count_h5objref,sizeof(hobj_ref_t));
-
- if(alldim_refdat == NULL) {
- printf("error in allocating memory. \n");
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- return FAIL;
- }
-
- for(i=0;i<count_h5objref;i++){
- h4toh5_ZeroMemory(h5newsdsdim_name,MAX_DIM_NAME);
- strcpy(h5newsdsdim_name,&h5sdsdim_allname[i*MAX_DIM_NAME]);
-
- ret = H5Rcreate(&dim_refdat,sh5_dimgroup,h5newsdsdim_name,
- H5R_OBJECT,-1);
- if(ret <0) {
- free(alldim_refdat);
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- printf("error in generating H5 reference. \n");
- return FAIL;
- }
- alldim_refdat[i] = dim_refdat;
-
- }
-
- attribID = H5Acreate(sh5dset,DIMSCALE,attr_refType,attr_refSpace,
- H5P_DEFAULT);
- if(attribID < 0) {
- free(alldim_refdat);
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- H5Aclose(attribID);
- printf("error in generating H5 attribute ID. \n");
- return FAIL;
- }
-
- ret = H5Awrite(attribID,attr_refType,(void *)alldim_refdat);
-
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- H5Aclose(attribID);
- free(alldim_refdat);
- }
-
- if(count_h5attrname!= 0) {
-
- h5dim_namesid = H5Screate_simple(1,h5dim_dims,NULL);
-
- if(h5dim_namesid <0) {
- printf("error in creating sds dimensionlist space.\n");
- return FAIL;
- }
-
- h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_SPACEPAD);
- if(h5str_dimntype < 0) {
- H5Sclose(h5dim_namesid);
- printf("error in generating H5T_STRING type.\n");
- return FAIL;
- }
-
- h5dim_nameaid = H5Acreate(sh5dset,HDF4_DIMENSION_LIST,h5str_dimntype,
- h5dim_namesid,H5P_DEFAULT);
-
- if(h5dim_nameaid <0) {
- H5Sclose(h5dim_namesid);
- printf("error in creating sds dimensionlist id.\n");
- return FAIL;
- }
-
- ret = H5Awrite(h5dim_nameaid,h5str_dimntype,h5sdsdim_allname);
-
- if(ret < 0) {
- H5Sclose(h5dim_namesid);
- H5Aclose(h5dim_nameaid);
- printf("error in writing sds dimensionlist. \n");
- return FAIL;
- }
-
- ret = H5Sclose(h5dim_namesid);
- ret = H5Aclose(h5dim_nameaid);
-
- }
- return SUCCEED;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/h4toh5test.c b/tools/h4toh5test.c
deleted file mode 100644
index 1f21b63..0000000
--- a/tools/h4toh5test.c
+++ /dev/null
@@ -1,3944 +0,0 @@
-/*** this code is to generate various hdf files to test h4toh5 converter and h4toh5 lib API. The code itself is NOT optimizied but try to consider various cases that examine how converter works. */
-
-#include "hdf.h"
-#include "mfhdf.h"
-#include <stdio.h>
-
-
-#define FILESDS1 "sds_typ_test.hdf"
-#define FILESDS2 "sds_dim_test.hdf"
-#define FILESDS3 "sds_attr_test.hdf"
-#define FILEGR "gr_typ_test.hdf"
-#define FILERAS8 "ras_8_test.hdf"
-#define FILERAS24 "ras_24_test.hdf"
-#define FILEGRPAL "image_attr_test.hdf"
-#define FILEVD "vdata_test.hdf"
-#define FILECLASHVG "vgnameclash_test.hdf"
-#define FILECLASHSDS "sdsnameclash_test.hdf"
-#define FILECLASHVD "vdnameclash_test.hdf"
-#define FILECLASHGR "grnameclash_test.hdf"
-#define FILELOOP "vg_loop_test.hdf"
-#define FILEHL "vg_hl_test.hdf"
-#define FILEVG "vg_all_test.hdf"
-#define FILEANNO "anno_test.hdf"
-
-/* for testing sds*/
-#define TYP_RANK 3
-#define TYP_DIMSIZE 4
-#define INT8_UPLIMIT 0x7E
-#define UINT8_UPLIMIT 0xFC
-#define INT16_UPLIMIT 0x7FFE
-#define UINT16_UPLIMIT 0xFFFC
-#define INT32_UPLIMIT 0x7FFFFFFE
-#define UINT32_UPLIMIT 0xFFFFFFFC
-#define ATT_SIZE 10
-
-/* for testing image*/
-#define X_LENGTH 10
-#define Y_LENGTH 5
-#define NUM_COLORS 256
-#define F_ATT1_NAME "File Attribute"
-#define RI_ATT1_NAME "Image Attribute"
-#define F_ATT1_VAL "Contents of First FILE Attribute"
-#define F_ATT1_N_VALUES 32
-#define RI_ATT1_VAL "Contents of IMAGE's First Attribute"
-#define RI_ATT1_N_VALUES 35
-
-/* for testing vdata*/
-#define NRECORDS 10
-#define FIELD_1 "Temp"
-#define FIELD_2 "Height"
-#define FIELD_3 "Speed"
-#define FIELD_4 "Ident"
-#define FIELD_5 "Position"
-#define FIELD_NAMES "Temp,Height,Speed,Ident,Position"
-#define FIELD_VDNAMES "Temp,Height"
-
-/*for testing vgroup*/
-#define VGATTR_NAME "Vgroup attribute 1"
-int test_sdstyp(void);
-int test_sdsdim(void);
-int test_sdsattr(void);
-int test_grtyp(void);
-int test_ras8(void);
-int test_ras24(void);
-int test_imageattr(void);
-int test_vdata(void);
-int test_vgnameclash(void);
-int test_sdsnameclash(void);
-int test_grnameclash(void);
-int test_vdnameclash(void);
-int test_vgloop(void);
-int test_vghl(void);
-int test_vgall(void);
-int test_anno(void);
-
-int main(void) {
- if(test_sdstyp()== FAIL) {
- printf("failed to create sds_typ_test.hdf file.\n");
- return FAIL;
- }
- if(test_sdsdim()== FAIL) {
- printf("failed to create sds_dim_test.hdf file. \n");
- return FAIL;
- }
- if(test_sdsattr()== FAIL) {
- printf("failed to create sds_attr_test.hdf file. \n");
- return FAIL;
- }
- if(test_grtyp()==FAIL) {
- printf("failed to create gr_typ_test.hdf file. \n");
- return FAIL;
- }
-
- if(test_ras8()==FAIL) {
- printf("failed to create ras8_test.hdf file.\n");
- return FAIL;
- }
-
- if(test_ras24()==FAIL) {
- printf("failed to create ras24_test.hdf file.\n");
- return FAIL;
- }
- if(test_imageattr()== FAIL) {
- printf("failed to create image_attr_test.hdf file.\n");
- return FAIL;
- }
-
- if(test_vdata()== FAIL) {
- printf("failed to create vdata_test.hdf file.\n");
- return FAIL;
- }
-
- if(test_vgnameclash()==FAIL) {
- printf("failed to create vg_nameclash.hdf file.\n");
- return FAIL;
- }
-
- if(test_sdsnameclash()==FAIL) {
- printf("failed to create sds_nameclash.hdf file.\n");
- return FAIL;
- }
-
- if(test_grnameclash()==FAIL) {
- printf("failed to create gr_nameclash.hdf file. \n");
- return FAIL;
- }
-
- if(test_vdnameclash()==FAIL) {
- printf("failed to create vd_nameclash.hdf file.\n");
- return FAIL;
- }
- if(test_vgloop()==FAIL) {
- printf("failed to create vg_loop.hdf file. \n");
- return FAIL;
- }
- if(test_vghl()==FAIL) {
- printf("failed to create vg_hl.hdf file. \n");
- return FAIL;
- }
- if(test_vgall()==FAIL) {
- printf("failed to create vg_all.hdf file. \n");
- return FAIL;
- }
- if(test_anno()==FAIL) {
- printf("failed to create vg_anno.hdf file. \n");
- return FAIL;
- }
- return 0;
-}
-
-/* this subroutine will hdf file with typical sds objects,
-
- The rank is TYP_RANK, each dimensional size is TYP_DIMSIZE.
- Datatype we are testing is:
- char,
- int8,
- int16,
- int32,
- uint16,
- uint32,
- lint16,
- lint32,
- luint32,
- float32,
- float64,
-
-*/
-int test_sdstyp(){
-
- int32 file_id,sds_id;
- int32 i,j,k;
- int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
- char8 typchar_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int8 typint8_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int16 typint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 typint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- uint16 typuint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 typlint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- uint32 typluint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- float32 typfloat32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- float64 typfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- float64 typlfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 typ_dims[TYP_RANK];
- int32 CUB_SIZE;
- int istat;
- /* TYPICAL sds array, we limit the dimensional size for testing purpose. */
-
- CUB_SIZE = (TYP_DIMSIZE-1)*(TYP_DIMSIZE-1)*(TYP_DIMSIZE-1);
-
- /* 1. data type is char */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++){
- typchar_array[i][j][k]=(char) (i+j+k);
- }
-
- /* data type is int8 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typint8_array[i][j][k]= (int8)(INT8_UPLIMIT-i*j*k*2/CUB_SIZE*INT8_UPLIMIT +1);
-
- /* data type is int16 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typint16_array[i][j][k]= (int16)(INT16_UPLIMIT-i*j*k*2/CUB_SIZE*INT16_UPLIMIT +1);
-
- /* data type is uint16 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typuint16_array[i][j][k]= (uint16)(UINT16_UPLIMIT-i*j*k*2/CUB_SIZE*(UINT16_UPLIMIT/2)+1);
-
- /* data type is int32 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typint32_array[i][j][k]= INT32_UPLIMIT-i*j*k*2/CUB_SIZE*INT32_UPLIMIT +1;
-
- /*data type is little-endian int32*/
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typlint32_array[i][j][k]= INT32_UPLIMIT-i*j*k*2/CUB_SIZE*INT32_UPLIMIT +1;
-
- /* data type is unsigned little-endian int32*/
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typluint32_array[i][j][k]= (uint32)(UINT32_UPLIMIT-i*j*k/CUB_SIZE*UINT32_UPLIMIT+1);
-
- /* data type is float32 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typfloat32_array[i][j][k]= 1.0+i+j+k;
-
- /* data type is float64 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typfloat64_array[i][j][k]= 1.0+i+j+k;
-
- /* data type is lfloat64 */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typlfloat64_array[i][j][k]= 1.0+i+j+k;
-
- for(i=0;i<TYP_RANK;i++){
- typ_dims[i] = TYP_DIMSIZE;
- typ_start[i] = 0;
- typ_edges[i] = TYP_DIMSIZE;
- typ_stride[i] = 1;
- }
-
- file_id = SDstart(FILESDS1,DFACC_CREATE);
-
- if(file_id == FAIL) {
- printf (" open file failed\n");
- return FAIL;
- }
-
- /* we also test different dimensional scale setting for typical array. */
- sds_id = SDcreate(file_id,"sds_char",DFNT_CHAR8,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typchar_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_int8",DFNT_INT8,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint8_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_int16",DFNT_INT16,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint16_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_int32",DFNT_INT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typint32_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_uint16",DFNT_UINT16,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typuint16_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_lint32",DFNT_LINT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typlint32_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_luint32",DFNT_LUINT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typluint32_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_float32",DFNT_FLOAT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typfloat32_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_float64",DFNT_FLOAT64,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typfloat64_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(file_id,"sds_lfloat64",DFNT_LFLOAT64,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typlfloat64_array);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
- SDend(file_id);
- return 0;
-}
-/* generating a hdf file with sds dimensional scale dataset in it.
- both limited and unlimited dimensions are provided.*/
-int test_sdsdim() {
-
- int32 file_id,sds_id,dim_id;
- int32 i,j,k;
- int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
- int32 typ_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 typ_dims[TYP_RANK];
- int32 dim_sca0[TYP_DIMSIZE];
- int32 istat;
-
- char dim_name0[] = "dim0";
- char dim_name1[] = "dim1";
- char dim_name2[] = "dim2";
-
- char unldim_name0[] ="unldim0";
- char unldim_name1[]="unldim1";
- char unldim_name2[]="unldim2";
-
- /* typical sds array. */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typ_array[i][j][k] = i+j+k;
-
- for (i=0;i<TYP_DIMSIZE;i++)
- dim_sca0[i] = i;
-
-
- for(i=0;i<TYP_RANK;i++){
- typ_dims[i] = TYP_DIMSIZE;
- typ_start[i] = 0;
- typ_edges[i] = TYP_DIMSIZE;
- typ_stride[i] = 1;
- }
-
- file_id = SDstart(FILESDS2,DFACC_CREATE);
-
- if(file_id == FAIL){
- printf (" open file failed\n");
- return FAIL;
- }
-
- /* testing for normal dimensional scale dataset. */
- sds_id = SDcreate(file_id,"sds_dimnor",DFNT_INT32,TYP_RANK,typ_dims);
-
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
-
-
- istat=SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
-
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
-
- for (i =0;i<TYP_RANK;i++){
- dim_id = SDgetdimid(sds_id,i);
-
- if(dim_id == FAIL) {
- printf("failed to generate dimensional id.\n");
- return FAIL;
- }
-
- switch(i) {
-
- case 0:
- istat = SDsetdimname(dim_id,dim_name0);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat =SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- case 1:
- istat = SDsetdimname(dim_id,dim_name1);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- case 2:
- istat = SDsetdimname(dim_id,dim_name2);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,typ_dims[2],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- }
-
- }
- SDendaccess(sds_id);
-
- /* for unlimited dimensional scale data. */
-
- typ_dims[0] = SD_UNLIMITED;
-
- sds_id = SDcreate(file_id,"sds_dimunl",DFNT_INT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
-
- istat =SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
- if(istat == FAIL) {
- printf("failed to write sds object. \n");
- return FAIL;
- }
- for (i =0;i<TYP_RANK;i++){
- dim_id = SDgetdimid(sds_id,i);
- if(dim_id == FAIL) {
- printf("failed to generate dimensional id.\n");
- return FAIL;
- }
- switch(i) {
-
- case 0:
- istat= SDsetdimname(dim_id,unldim_name0);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- /* SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);*/
- istat= SDsetdimscale(dim_id,TYP_DIMSIZE,DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- case 1:
- istat= SDsetdimname(dim_id,unldim_name1);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- case 2:
- istat = SDsetdimname(dim_id,unldim_name2);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,typ_dims[2],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- break;
- }
- }
- SDendaccess(sds_id);
-
- SDend(file_id);
- return 0;
-}
-
-/* a hdf file that includes sds predefined attributes, dimensional
- scale attributes and chunking and compress information*/
-int test_sdsattr() {
-
- int32 file_id,sds_id,dim_id;
- int32 i,j,k,comp_flag;
- int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK];
- int32 typ_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 typ_dims[TYP_RANK];
- int32 fill_value;
- int32 dim_sca0[TYP_DIMSIZE],dim_sca1[TYP_DIMSIZE];
-
- HDF_CHUNK_DEF c_def;
- int32 comp_type;
- comp_info c_info;
- int32 istat;
- float64 cal;
- float64 cal_err;
- float64 offset;
- float64 offset_err;
-
- char* attr_value;
- char* gloattr_value;
- char label[] = "sds.label";
- char unit[] = "sds.unit";
- char format[] = "sds.format";
- char coordsys[] = "sds.coord";
-
- char dim_name0[] ="dim0";
- char dim_name1[] ="dim1";
- char dim_label[] ="dim.label";
- char dim_unit[] ="dim.unit";
- char dim_format[] ="dim.format";
-
- /**** initial setting. ****/
- cal = 1.0;
- cal_err = 0.0;
- offset = 0.0;
- offset_err = 0.0;
- fill_value = 999;
-
-
- /* typical sds array. */
- for (i=0;i<TYP_DIMSIZE;i++)
- for (j=0;j<TYP_DIMSIZE;j++)
- for (k=0;k<TYP_DIMSIZE;k++)
- typ_array[i][j][k]= i+j+k;
-
- attr_value = malloc(ATT_SIZE*sizeof(char));
- if(attr_value == NULL) {
- printf("failed to allocate memory. \n");
- return FAIL;
- }
-
- gloattr_value = malloc(ATT_SIZE*sizeof(char));
- if(gloattr_value == NULL) {
- printf("failed to allocate memory. \n");
- return FAIL;
- }
-
- strcpy(gloattr_value,"glo attr");
- strcpy(attr_value,"test attr");
-
- for(i=0;i<TYP_RANK;i++){
- typ_dims[i] = TYP_DIMSIZE;
- typ_start[i] = 0;
- typ_edges[i] = TYP_DIMSIZE;
- typ_stride[i] = 1;
- }
-
- for (i=0;i<TYP_DIMSIZE;i++){
- dim_sca0[i] = i;
- dim_sca1[i] = 2*i;
- }
- file_id = SDstart(FILESDS3,DFACC_CREATE);
-
- if(file_id == FAIL) {
- printf (" open file failed\n");
- return FAIL;
- }
-
- istat = SDsetattr(file_id,"sds.gloattr",DFNT_CHAR8,10,(VOIDP)gloattr_value);
- if(istat == FAIL) {
- printf("failed to set attribute.\n");
- return FAIL;
- }
-
- istat = SDsetfillmode(file_id,SD_NOFILL);
-
- if (istat == FAIL) {
- printf("error setting fill mode\n");
- return FAIL;
- }
-
- sds_id = SDcreate(file_id,"sds_attr",DFNT_INT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
-
- istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
- if (istat == FAIL){
- printf("error setting fill value\n");
- return FAIL;
- }
-
- istat = SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
-
- if(istat == FAIL) {
- printf("failed to write sds data.\n");
- return FAIL;
- }
- /*** write dataset attribute ***/
-
- istat = SDsetattr(sds_id,"sds.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
- if(istat == FAIL) {
- printf(" sds data attr. setting failed. \n");
- return FAIL;
- }
- /*** write dataset predefined attribute ***/
-
- istat = SDsetdatastrs(sds_id,label,unit,format,coordsys);
- if(istat == FAIL) {
- printf(" sds data predefined attr. setting failed. \n");
- return FAIL;
- }
- /*** set calibration information. ***/
-
- istat = SDsetcal(sds_id,cal,cal_err,offset,offset_err,DFNT_INT32);
- if(istat == FAIL) {
- printf(" sds data calibrating attr. setting failed. \n");
- return FAIL;
- }
- for (i =0; i<TYP_RANK;i++) {
- dim_id = SDgetdimid(sds_id,i);
- if(dim_id == FAIL) {
- printf("sds set dim id failed. \n");
- return FAIL;
- }
- if (i==0) {
- istat = SDsetdimname(dim_id,dim_name0);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat=SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- }
- else {
- istat = SDsetdimname(dim_id,dim_name1);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca1);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- }
-
- istat = SDsetdimstrs(dim_id,dim_label,dim_unit,dim_format);
- if(istat == FAIL) {
- printf("sds set dim. predefined attr. failed. \n");
- return FAIL;
- }
- istat = SDsetattr(dim_id,"sdsdim.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
-
- if(istat == FAIL) {
- printf(" sds dim data attr. setting failed. \n");
- return FAIL;
- }
- SDendaccess(dim_id);
- }
-
- SDendaccess(sds_id);
-
-
- sds_id = SDcreate(file_id,"sds_compress",DFNT_INT32,TYP_RANK,typ_dims);
- if(sds_id == FAIL) {
- printf("failed to create object.\n");
- return FAIL;
- }
- comp_type = COMP_CODE_DEFLATE;
- c_info.deflate.level = 3;
-
- c_def.comp.chunk_lengths[0] = 2;
- c_def.comp.chunk_lengths[1] = 2;
- c_def.comp.chunk_lengths[2] = 2;
- c_def.comp.comp_type = COMP_CODE_DEFLATE;
-
- comp_flag = HDF_CHUNK;
-
- c_def.comp.cinfo.deflate.level = 3;
-
- istat = SDsetchunk(sds_id,c_def,comp_flag);
- if(istat == FAIL) {
- printf("chunking is not setting properly. \n");
- return FAIL;
- }
-
-
- istat = SDwritedata(sds_id,typ_start,typ_stride,typ_edges,(VOIDP)typ_array);
- if(istat == FAIL) {
- printf("SDS cannot write chunking and compression mode. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- SDend(file_id);
- free(attr_value);
- free(gloattr_value);
- return 0;
-}
-
-/***** routines for generating gr datatype hdf testing file.
- we are only generating one and three components for
- datatype
- uint32 and int16. ****/
-int test_grtyp() {
-
- int32 gr_id, ri_id, file_id, il;
- int32 ncomp;
- int32 start[2], edges[2],dims[2];
- uint32 image_data32[Y_LENGTH][X_LENGTH][3];
- uint32 image_data321[Y_LENGTH][X_LENGTH];
- int16 image_data16[Y_LENGTH][X_LENGTH][3];
- int16 image_data161[Y_LENGTH][X_LENGTH];
- intn i, j;
- int32 CUB_SIZE;
- int istat;
-
- CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
-
- /* 3-component GR image data type UINT32*/
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data32[j][i][0] = UINT32_UPLIMIT - i*j*0/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
- image_data32[j][i][1] = UINT32_UPLIMIT - i*j*1/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
- image_data32[j][i][2] = UINT32_UPLIMIT - i*j*2/CUB_SIZE*(UINT32_UPLIMIT/2)+1;
-
- }
- }
-
- /* 3-component GR image data type int16*/
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data16[j][i][0] = INT16_UPLIMIT - i*j*0/CUB_SIZE*(INT16_UPLIMIT/2)+1;
- image_data16[j][i][1] = INT16_UPLIMIT - i*j*1/CUB_SIZE*(INT16_UPLIMIT/2)+1;
- image_data16[j][i][2] = INT16_UPLIMIT - i*j*2/CUB_SIZE*(INT16_UPLIMIT/2)+1;
-
- }
- }
-
- /* 1-component GR image data type uint32 */
- for (j = 0; j < Y_LENGTH; j++)
- for (i = 0; i < X_LENGTH; i++)
- image_data321[j][i] = UINT32_UPLIMIT - i*j/CUB_SIZE*UINT32_UPLIMIT+1;
-
- /* 1-component GR image data type int16*/
- for (j = 0; j < Y_LENGTH; j++)
- for (i = 0; i < X_LENGTH; i++)
- image_data161[j][i] = INT16_UPLIMIT - i*j/CUB_SIZE*INT16_UPLIMIT+1;
-
-
- /* Open the file. */
- file_id = Hopen(FILEGR, DFACC_CREATE, 0);
-
- if(file_id == FAIL) {
- printf("fail to create GR file.\n");
- return FAIL;
- }
- /* Initiate the GR interface. */
- gr_id = GRstart(file_id);
-
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_uint32", ncomp, DFNT_UINT32, il, dims);
-
- if(ri_id == FAIL) {
- printf("fail to create RI interface.\n");
- return FAIL;
- }
-
- /* Define the location, pattern, and size of the data set */
- for (i = 0; i < 2; i++) {
- start[i] = 0;
- edges[i] = dims[i];
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- /* Terminate access to the image. */
- GRendaccess(ri_id);
-
- /* For number of components =3, data type is int16*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_int16", ncomp, DFNT_INT16, il, dims);
-
- if(ri_id == FAIL) {
- printf("fail to create RI interface.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data16);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- /* Terminate access to the image. */
- GRendaccess(ri_id);
-
- /* For number of components =1, data type is uint32*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 1;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_uint321", ncomp, DFNT_UINT32, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create RI interface.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data321);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- /* Terminate access to the image. */
- GRendaccess(ri_id);
-
-
- /* For number of components = 1, data type is int16*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 1;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_int161", ncomp, DFNT_INT16, il, dims);
-
- if(ri_id == FAIL) {
- printf("fail to create RI interface.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data161);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- /* Terminate access to the image. */
- GRendaccess(ri_id);
- /* Terminate access to the GR interface. */
- GRend(gr_id);
-
- /* Close the file. */
- Hclose(file_id);
- return 0;
-}
-
-
-/***** routine to generate raster 8 bit data type hdf file. ****/
-int test_ras8() {
-
- int32 gr_id, ri_id, file_id, il,istat;
- int32 ncomp;
- int32 start[2], edges[2],dims[2];
- int8 image_data8[Y_LENGTH][X_LENGTH];
- uint8 image_datau8[Y_LENGTH][X_LENGTH];
- intn i, j;
- int32 CUB_SIZE;
-
- CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
-
- /* 1-component Raster-8 image data type uint8 */
- for (j = 0; j < Y_LENGTH; j++)
- for (i = 0; i < X_LENGTH; i++)
- image_datau8[j][i] = UINT8_UPLIMIT - i*j/CUB_SIZE*UINT8_UPLIMIT+1;
-
- /* 1-component Raster-8 image data type int8*/
- for (j = 0; j < Y_LENGTH; j++)
- for (i = 0; i < X_LENGTH; i++)
- image_data8[j][i] = INT8_UPLIMIT - i*j/CUB_SIZE*INT8_UPLIMIT+1;
-
- /* Open the file. */
- file_id = Hopen(FILERAS8, DFACC_CREATE, 0);
-
- if(file_id == FAIL) {
- printf("fail to open raster 8 file.\n");
- return FAIL;
- }
- /* Initiate the GR interface. */
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
- /* For number of components = 1, data type is uint8*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 1;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_uint8", ncomp, DFNT_UINT8, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_datau8);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- istat = GRendaccess(ri_id);
- if(istat == FAIL) {
- printf("fail in ending RI interface.\n");
- return FAIL;
- }
-
- /* For number of components = 1, data type is int8*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 1;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_int8", ncomp, DFNT_INT8, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data8);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- GRendaccess(ri_id);
- /* Terminate access to the GR interface. */
- GRend(gr_id);
-
- /* Close the file. */
- Hclose(file_id);
- return 0;
-}
-
-/***** routine to generate raster 24 bit data type hdf file. ****/
-int test_ras24() {
-
- int32 gr_id, ri_id, file_id, il;
- int32 ncomp,istat;
- int32 start[2], edges[2],dims[2];
- int8 image_data24[Y_LENGTH][X_LENGTH][3];
- uint8 image_datau24[Y_LENGTH][X_LENGTH][3];
- intn i, j;
- int32 CUB_SIZE;
-
-
- CUB_SIZE = (X_LENGTH-1)*(Y_LENGTH-1);
-
- /* 3-component Raster-8 image data type uint8 */
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_datau24[j][i][0] = UINT8_UPLIMIT - i*j*0/CUB_SIZE*UINT8_UPLIMIT+1;
- image_datau24[j][i][1] = UINT8_UPLIMIT - i*j*1/CUB_SIZE*(UINT8_UPLIMIT/2)+1;
- image_datau24[j][i][2] = UINT8_UPLIMIT - i*j*2/CUB_SIZE*(UINT8_UPLIMIT/2)+1;
- }
- }
- /* 3-component Raster-8 image data type int8*/
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data24[j][i][0] = INT8_UPLIMIT - i*j*0/CUB_SIZE*INT8_UPLIMIT+1;
- image_data24[j][i][1] = INT8_UPLIMIT - i*j*1/CUB_SIZE*(INT8_UPLIMIT/2)+1;
- image_data24[j][i][2] = INT8_UPLIMIT - i*j*2/CUB_SIZE*(INT8_UPLIMIT/2)+1;
-
- }
- }
-
- /* Open the file. */
- file_id = Hopen(FILERAS24, DFACC_CREATE, 0);
-
- if(file_id == FAIL) {
- printf("fail to open the file. \n");
- return FAIL;
- }
-
- /* Initiate the GR interface. */
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
-
- /* For number of components = 3, data type is uint8*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_uint24", ncomp, DFNT_UINT8, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_datau24);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- /* Terminate access to the image. */
- GRendaccess(ri_id);
-
-
- /* For number of components = 3, data type is int8*/
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_int24", ncomp, DFNT_INT8, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data24);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- GRendaccess(ri_id);
- /* Terminate access to the GR interface. */
- GRend(gr_id);
-
- /* Close the file. */
- Hclose(file_id);
- return 0;
-}
-
-/* routine to generate image attribute file.*/
-int test_imageattr() {
-
- int32 gr_id, ri_id, file_id, il,pal_id,istat;
- int32 ncomp,data_type;
- int32 start[2], edges[2],dims[2];
- uint16 image_data[Y_LENGTH][X_LENGTH][3];
-
- uint8 palette_data[NUM_COLORS * 3];
- int32 num_comp,num_entries;
- intn i, j;
- char* ri_attrname;
- char*file_attrname;
-
- /* Open the file. */
- file_id = Hopen(FILEGRPAL, DFACC_CREATE, 0);
-
- /* Initiate the GR interface. */
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- dims[0] = X_LENGTH;
- dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_1", ncomp, DFNT_UINT16, il, dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
- /* Fill the stored-data array with values. */
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data[j][i][0] = i+j+1;
- image_data[j][i][1] = (i+j)*2;
- image_data[j][i][2] = (i+j)*3;
- }
- }
-
- /* Define the location, pattern, and size of the data set */
- for (i = 0; i < 2; i++) {
- start[i] = 0;
- edges[i] = dims[i];
- }
-
- /* set GR global attribute. */
-
- file_attrname=malloc(strlen(F_ATT1_NAME));
- strcpy(file_attrname,F_ATT1_NAME);
- istat = GRsetattr(gr_id,file_attrname,DFNT_CHAR8,F_ATT1_N_VALUES,(VOIDP)F_ATT1_VAL);
- if(istat == FAIL) {
- printf("fail to set GR global attribute.\n");
- return FAIL;
- }
- /* set GR attribute. */
- ri_attrname=malloc(strlen(RI_ATT1_NAME));
- strcpy(ri_attrname,RI_ATT1_NAME);
- istat = GRsetattr(ri_id,ri_attrname,DFNT_CHAR8,RI_ATT1_N_VALUES,(VOIDP)RI_ATT1_VAL);
- if(istat == FAIL) {
- printf("fail to set GR attribute.\n");
- return FAIL;
- }
- free(file_attrname);
- free(ri_attrname);
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Initialize the palette to grayscale. */
- for (i = 0; i < NUM_COLORS; i++) {
- palette_data[i * 3] = i;
- palette_data[i * 3 + 1] = i;
- palette_data[i * 3 + 2] = i;
- }
-
- /* Set palette characteristics. */
- data_type = DFNT_UINT8;
- num_entries = NUM_COLORS;
- num_comp = 3;
-
- /* Get the id for the palette. */
- pal_id = GRgetlutid(ri_id,0 );
- if(pal_id == FAIL) {
- printf("fail to obtain palette id.\n");
- return FAIL;
- }
-
- /* Write the palette to file. */
- istat = GRwritelut(pal_id, num_comp, data_type,
- 0, num_entries,
- (VOIDP)palette_data);
- if(istat == FAIL) {
- printf("fail to write lookup table.\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- GRendaccess(ri_id);
-
- /* Terminate access to the GR interface. */
- GRend(gr_id);
-
- /* Close the file. */
- Hclose(file_id);
- return 0;
-}
-
-/* routines to generate vdata hdf testing file. */
-int test_vdata( )
-{
-
- struct {
- float32 temp;
- int16 height;
- float32 speed;
- char ident[3];
- float32 position[2];
- } source[NRECORDS];
-
- int32 file_id, vdata_id, istat, values[4] ={32, 16, 32, 8};
- uint8 *databuf, *pntr;
- int i,j, bufsize, recsize;
- VOIDP fldbufpt[5];
-
- /* Open the HDF file. */
- file_id = Hopen(FILEVD, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open HDF file.\n");
- return FAIL;
- }
-
- /* Initialize the Vset interface. */
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start V interface.\n");
- return FAIL;
- }
-
- /* Create a new Vdata. */
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach Vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define field1 \n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define field2 \n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_3, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define field3 \n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_4, DFNT_CHAR8, 3);
- if(istat == FAIL) {
- printf("fail to define field4 \n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_5, DFNT_FLOAT32,2);
- if(istat == FAIL) {
- printf("fail to define field5 \n");
- return FAIL;
- }
-
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name\n");
- return FAIL;
- }
-
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class\n");
- return FAIL;
- }
-
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_NAMES);
- if(istat == FAIL) {
- printf("fail to set fields of vdata.\n");
- return FAIL;
- }
-
- recsize = (2 * sizeof(float32) + sizeof(int16))+ 2* sizeof(float32)
- +3*sizeof(char);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc memory for vdata failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
- source[i].speed = 1.11 * (i+1);
- source[i].ident[0] = 'A' + i;
- source[i].ident[1] = 'a' + i;
- source[i].ident[2] ='0'+i;
- for (j=0; j< 2; j++)
- source[i].position[j] = 1.0+j;
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- fldbufpt[2] = &source[i].speed;
- fldbufpt[3] = &source[i].ident[0];
- fldbufpt[4] = &source[i].position[0];
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- /* Set Vdata attribute */
- istat = VSsetattr (vdata_id, _HDF_VDATA, "vdata attr", DFNT_INT32, 4, (VOIDP)values);
- if(istat == FAIL) {
- printf("fail to set vdata attribute.\n");
- return FAIL;
- }
- /* Set attribute for "speed" field */
- istat = VSsetattr (vdata_id, 2, "field attr", DFNT_CHAR, 3, "MAX");
- if(istat == FAIL) {
- printf("fail to set vdata field attribute.\n");
- return FAIL;
- }
- /*
- * Terminate access to the Vdata, the Vset interface
- * and the HDF file.
- */
- VSdetach(vdata_id);
- Vend(file_id);
- Hclose(file_id);
- free(databuf);
- return 0;
-}
-
-/* this routine will generate hdf file that has name clashings for different
- vgroups.
-
- two situations:
- 1. two groups share the same name.
- 2. one group doesn't have name.
-
- */
-int test_vgnameclash() {
-
- int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
- int32 vgroupc_id,vgroupc_ref;
- int32 dim_sizes[TYP_RANK];
- intn i, j;
- int32 sd_id,sds_id;
- int32 sds_ref;
- int32 array_data[X_LENGTH][Y_LENGTH];
- int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
- int istat;
-
- for (i=0;i<X_LENGTH;i++){
- for(j=0;j<Y_LENGTH;j++) {
- array_data[i][j] =i+j;
- }
- }
-
- dim_sizes[0] = X_LENGTH;
- dim_sizes[1] = Y_LENGTH;
-
- for (i=0;i<TYP_RANK;i++){
- stride[i]=1;
- start[i]=0;
- edges[i]=dim_sizes[i];
-
- }
-
- /* Open the HDF file. */
-
- /* We are testing name clashings for vgroups.*/
-
- /* two situations:
- 1. two groups share the same name.
- 2. one group doesn't have name. */
-
- file_id = Hopen(FILECLASHVG, DFACC_CREATE, 0);
- if (file_id == FAIL) {
- printf("fail to open vg_clash.hdf.\n");
- return FAIL;
- }
-
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vgroup interface.\n");
- return FAIL;
- }
- vgroupa_ref = -1;
- vgroupb_ref = -1;
- vgroupc_ref = -1;
- vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach groupa.\n");
- return FAIL;
- }
- vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach groupb.\n");
- return FAIL;
- }
- vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
- if(vgroupc_id == FAIL) {
- printf("fail to attach groupc.\n");
- return FAIL;
- }
- istat=Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
-
- istat=Vsetname(vgroupb_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupb.\n");
- return FAIL;
- }
- sd_id = SDstart(FILECLASHVG,DFACC_WRITE);
- if(sd_id == FAIL) {
- printf("fail to start SD interface.\n");
- return FAIL;
- }
-
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
- SDend(sd_id);
- Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
- istat = Vdetach(vgroupc_id);
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-
-/* This routine creates different SDS objects with name clashing.
-We are testing different SDS
- 1. under the same group sharing the same name.
- 2. one sds doesn't have name.
- 3. different sds objects under different vgroups sharing the same name.
- 4. sds objects under no specific groups share the same name.
- 5. sds objects under no specific groups with no name. */
-
-
-int test_sdsnameclash() {
-
-
- int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
- int32 dim_sizes[TYP_RANK];
- int32 vgroupc_ref,vgroupc_id;
- intn i, j,istat;
- int32 sd_id,sds_id;
- int32 sds_ref;
- int32 array_data[X_LENGTH][Y_LENGTH];
- int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
-
-
- for (i=0;i<X_LENGTH;i++){
- for(j=0;j<Y_LENGTH;j++) {
- array_data[i][j] =i+j;
- }
- }
-
- dim_sizes[0] = X_LENGTH;
- dim_sizes[1] = Y_LENGTH;
-
- for (i=0;i<TYP_RANK;i++){
- stride[i]=1;
- start[i]=0;
- edges[i]=dim_sizes[i];
-
- }
-
- /* Open the HDF file. */
-
- file_id = Hopen(FILECLASHSDS, DFACC_CREATE, 0);
- istat = Vstart(file_id);
- vgroupa_ref = -1;
- vgroupb_ref = -1;
- vgroupc_ref = -1;
- vgroupa_id = Vattach(file_id,vgroupa_ref,"w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach groupa.\n");
- return FAIL;
- }
- vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach groupb.\n");
- return FAIL;
- }
- vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
- if(vgroupc_id == FAIL) {
- printf("fail to attach groupc.\n");
- return FAIL;
- }
- istat=Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- istat=Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set name for groupb.\n");
- return FAIL;
- }
- Vsetname(vgroupc_id,"groupC");
- if(istat == FAIL) {
- printf("fail to set name for groupc.\n");
- return FAIL;
- }
- sd_id = SDstart(FILECLASHSDS,DFACC_WRITE);
- if(sd_id == FAIL) {
- printf("fail to start SD interface.\n");
- return FAIL;
- }
- /* putting one sds object under groupa. */
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
- /* a sds object with the name "sds" is put under group a.*/
- istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- /* putting another sds with the same same "sds" under groupa.
- It is legal for hdf lib. */
-
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
-
- /* no sds name is given under groupc*/
- sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupc_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
-
- /* another no name sds object is put under group c. */
- sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupc_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- /* another sds with the same name under groupb is given.*/
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("failed to transfer sds id to reference number.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add tag for reference.\n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- /* two sds share the same name under no specific groups.*/
- sds_id = SDcreate(sd_id,"sds_independent",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- sds_id = SDcreate(sd_id,"sds_independent",DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- /* another sds with no name and is not tagged with any group. */
- sds_id = SDcreate(sd_id,NULL,DFNT_INT32,2,dim_sizes);
- if(sds_id == FAIL) {
- printf("failed to create sds object.\n");
- return FAIL;
- }
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("failed to write sds data. \n");
- return FAIL;
- }
- SDendaccess(sds_id);
-
- SDend(sd_id);
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
- istat = Vdetach(vgroupc_id);
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-
-/*A routine to generate a testing file that deals with different
-name clashings for image.
-We are testing different Image
- 1. under the same group sharing the same name.
- 2. one image doesn't have name(not allowed)
- 3. different image objects under different vgroups sharing the same name.
- 4. image objects under no specific groups share the same name.
- 5. image objects under no specific groups with no name(not allowed). */
-
-
-int test_grnameclash() {
-
-
- int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id,istat;
- int32 dim_sizes[2];
-
- int i, j;
- int32 gr_id,ri_id,il,ncomp;
- int32 gr_ref;
- int32 start[2], edges[2];
- uint32 image_data32[Y_LENGTH][X_LENGTH][3];
-
- for (j=0;j<Y_LENGTH;j++){
- for(i=0;i<X_LENGTH;i++) {
- image_data32[j][i][0] = i;
- image_data32[j][i][1] = j;
- image_data32[j][i][2] = i+j;
- }
- }
-
- dim_sizes[0] = X_LENGTH;
- dim_sizes[1] = Y_LENGTH;
-
-
- /* Open the HDF file. */
-
- file_id = Hopen(FILECLASHGR, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open the file.\n");
- return FAIL;
- }
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vgroup interface.\n");
- return FAIL;
- }
- vgroupa_ref = -1;
- vgroupb_ref = -1;
-
- vgroupa_id = Vattach(file_id,vgroupa_ref,"w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach groupa.\n");
- return FAIL;
- }
- vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach groupb.\n");
- return FAIL;
- }
-
- istat=Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
-
- istat=Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set name for groupb.\n");
- return FAIL;
- }
-
- gr_id = GRstart(file_id);
-
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
- /* Define the location, pattern, and size of the data set */
- for (i = 0; i < 2; i++) {
- start[i] = 0;
- edges[i] = dim_sizes[i];
- }
- /* Define the number of components and dimensions of the image. */
- ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
-
- /* Create the array. */
- /* 1.1. put one image with the name "Imagea" under groupa.*/
- ri_id = GRcreate(gr_id, "Imagea", ncomp, DFNT_UINT32, il, dim_sizes);
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- gr_ref = GRidtoref(ri_id);
- if(gr_ref == FAIL) {
- printf("fail to convert ri_id into reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupa_id,DFTAG_RIG,gr_ref);
- if(istat == FAIL) {
- printf("fail to add gr object into vgroup a.\n");
- return FAIL;
- }
- GRendaccess(ri_id);
-
- /* 1.2 putting the same same image object under groupa. */
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Imagea", ncomp, DFNT_UINT32, il, dim_sizes);
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- gr_ref = GRidtoref(ri_id);
- if(gr_ref == FAIL) {
- printf("fail to convert ri_id into reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupa_id,DFTAG_RIG,gr_ref);
- if(istat == FAIL) {
- printf("fail to add gr object into vgroup a.\n");
- return FAIL;
- }
- GRendaccess(ri_id);
-
-
- /* 2.0 no image name is given, it is illegal for hdf4 lib; therefore;
- no test cases are given. */
-
-
- /* 3.1 another image with the "imagea" under groupb is given.*/
- ri_id = GRcreate(gr_id,"imagea", ncomp, DFNT_UINT32, il, dim_sizes);
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- gr_ref = GRidtoref(ri_id);
- if(gr_ref == FAIL) {
- printf("fail to convert ri_id into reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupb_id,DFTAG_RIG,gr_ref);
- if(istat == FAIL) {
- printf("fail to add gr object into vgroup a.\n");
- return FAIL;
- }
- GRendaccess(ri_id);
-
- /* 4.0 two images share the same name under no specific groups.*/
-
- ri_id = GRcreate(gr_id, "Image_independent", ncomp, DFNT_UINT32, il, dim_sizes);
-
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- GRendaccess(ri_id);
-
- ri_id = GRcreate(gr_id, "Image_independent", ncomp, DFNT_UINT32, il, dim_sizes);
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_data32);
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
- GRendaccess(ri_id);
- GRend(gr_id);
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
-
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-/* a routine that generates the name clashing for vdata object. some
- redundant codes can found in this routine, it should be corrected later.
-
- Cases:
-
- 1. two independent Vdata with the same name not under any user-specified group.
- 2. vdata without any names and not under any user-specified groups.
- 3. different Vdata objects under the same vgroup sharing the same name.
- 4. different Vdata objects under different vgroups sharing the same name.
- 5. Vdata without any names under one user-specified group*/
-
-int test_vdnameclash() {
-
- int32 file_id, vgroupa_ref, vgroupa_id,vgroupb_ref,vgroupb_id;
- int32 vgroupc_id,vgroupc_ref,vd_ref;
-
- struct {
- float32 temp;
- int16 height;
- } source[NRECORDS];
-
- int32 vdata_id, istat;
- uint8 *databuf, *pntr;
- int i, bufsize, recsize;
- VOIDP fldbufpt[2];
-
- /* Open the HDF file. */
- file_id = Hopen(FILECLASHVD, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open the file.\n");
- return FAIL;
- }
- /* Initialize the Vset interface. */
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vgroup interface.\n");
- return FAIL;
- }
-
- /* 1.0
- Create an independent new Vdata with the name "Test Vset Name". */
-
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata id.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
-
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
-
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
-
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("fail to allocate memory for databuf");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
-
- free(databuf);
- VSdetach(vdata_id);
-
- /* 1.1
- Create another independent Vdata with the name "Test Vset Name" */
-
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
-
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
-
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- free(databuf);
- VSdetach(vdata_id);
-
- /* An independent Vdata without name not under any user-specified vgroup. */
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata id.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- /* Set the Vdata class.
- istat=VSsetclass(vdata_id, "Test Vset Class");*/
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- free(databuf);
- VSdetach(vdata_id);
-
- vgroupa_ref = -1;
- vgroupb_ref = -1;
- vgroupc_ref = -1;
-
- /* 3. two vdata with the same name under groupa. */
- vgroupa_id = Vattach(file_id, vgroupa_ref,"w");
-
- Vsetname(vgroupa_id,"groupA");
- /* Create a new Vdata. */
- vdata_id = VSattach(file_id, -1, "w");
-
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name. \n");
- return FAIL;
- }
-
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- free(databuf);
- vd_ref = VSQueryref(vdata_id);
- if(vd_ref == FAIL) {
- printf("fail to query vdata.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupa_id,DFTAG_VH,vd_ref);
- if(istat == FAIL){
- printf("fail to add vdata into vgroup.\n");
- return FAIL;
- }
- VSdetach(vdata_id);
-
- /* Create a new Vdata. */
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
-
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
-
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- free(databuf);
- vd_ref = VSQueryref(vdata_id);
- if(vd_ref== FAIL) {
- printf("fail to query reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupa_id,DFTAG_VH,vd_ref);
- if(istat == FAIL) {
- printf("fail to add vdata into vgroup a.\n");
- return FAIL;
- }
- VSdetach(vdata_id);
-
-
- /*4. another vdata with the same name under groupb.*/
- vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach vgroup b.\n");
- return FAIL;
- }
-
- istat=Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set group b name.\n");
- return FAIL;
- }
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- /* Set the Vdata name. */
- istat=VSsetname(vdata_id, "Test Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
- /* Set the Vdata class. */
- istat=VSsetclass(vdata_id, "Test Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
-
- free(databuf);
- vd_ref = VSQueryref(vdata_id);
- if(vd_ref == FAIL) {
- printf("fail to query reference.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupb_id,DFTAG_VH,vd_ref);
- if(istat == FAIL) {
- printf("fail to add vdata into vgroup.\n");
- return FAIL;
- }
-
- VSdetach(vdata_id);
-
- /* 5. vdata without name under groupc. */
- vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
- if(vgroupc_id == FAIL) {
- printf("fail to attach vgroup c.\n");
- return FAIL;
- }
- istat = Vsetname(vgroupc_id,"groupC");
- if(istat == FAIL) {
- printf("fail to set group c name.\n");
- return FAIL;
- }
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_VDNAMES);
- if(istat == FAIL) {
- printf("fail to set field name.\n");
- return FAIL;
- }
-
- recsize = sizeof(float32) + sizeof(int16);
-
- bufsize = recsize * NRECORDS;
- databuf = (uint8 *) malloc((size_t)bufsize);
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
-
- }
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
-
- free(databuf);
- vd_ref = VSQueryref(vdata_id);
- if(vd_ref == FAIL) {
- printf("fail to get reference number for vata.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupc_id,DFTAG_VH,vd_ref);
- if(istat == FAIL) {
- printf("fail to add vdata into groupc.\n");
- return FAIL;
- }
- VSdetach(vdata_id);
-
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
- istat = Vdetach(vgroupc_id);
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-
-/* a routine that generates a hdf file with vgroup loops.va->vb and vb->va */
-
-int test_vgloop() {
-
- int32 file_id, vgroupa_ref, vgroupa_id, vgroupb_ref,vgroupb_id;
- int32 istat,dims[TYP_RANK];
- int i,j,k;
-
- /*2. for sds */
- int32 sd_id,sds_id;
- int32 sds_ref;
- int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
-
-
- for (i=0;i<TYP_DIMSIZE;i++){
- for(j=0;j<TYP_DIMSIZE;j++) {
- for(k=0;k<TYP_DIMSIZE;k++){
- array_data[i][j][k] =i+j;
- }
- }
- }
-
- dims[0] = TYP_DIMSIZE;
- dims[1] = TYP_DIMSIZE;
- dims[2] = TYP_DIMSIZE;
- for (i=0;i<TYP_RANK;i++){
- stride[i]=1;
- start[i]=0;
- edges[i]=dims[i];
-
- }
-
- /* Open the HDF file. */
-
- file_id = Hopen(FILELOOP, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open the file.\n");
- return FAIL;
- }
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vdata interface.\n");
- return FAIL;
- }
-
- vgroupa_ref = -1;
- vgroupb_ref = -1;
- vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach group a.\n");
- return FAIL;
- }
- vgroupb_id = Vattach(file_id, vgroupb_ref, "w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach groupb.\n");
- return FAIL;
- }
- istat = Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- istat = Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- istat = Vinsert(vgroupa_id,vgroupb_id);
- if(istat == FAIL) {
- printf("fail to insert groupb into groupa.\n");
- return FAIL;
- }
-
- istat = Vinsert(vgroupb_id,vgroupa_id);
- if(istat == FAIL) {
- printf("fail to insert groupa into groupb.\n");
- return FAIL;
- }
- sd_id = SDstart(FILELOOP,DFACC_WRITE);
- if(sd_id == FAIL) {
- printf("fail to start sd interface.\n");
- return FAIL;
- }
-
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,TYP_RANK,dims);
- if(sds_id == FAIL) {
- printf("fail to create sds interface.\n");
- return FAIL;
- }
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("fail to write sds data.\n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("fail to create sds reference.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add sds into vgroupa\n");
- return FAIL;
- }
- SDendaccess(sds_id);
- SDend(sd_id);
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-
-/* a routine that creates a hdf file which has one sds under two
- different vgroups. */
-int test_vghl() {
-
- int32 file_id, vgroupa_ref, vgroupa_id, vgroupb_ref,vgroupb_id;
- int32 istat,dims[TYP_RANK];
- int i,j,k;
-
- /*2. for sds */
- int32 sd_id,sds_id;
- int32 sds_ref;
- int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
-
- for (i=0;i<TYP_DIMSIZE;i++){
- for(j=0;j<TYP_DIMSIZE;j++) {
- for(k=0;k<TYP_DIMSIZE;k++){
- array_data[i][j][k] =i+j;
- }
- }
- }
-
- dims[0] = TYP_DIMSIZE;
- dims[1] = TYP_DIMSIZE;
- dims[2] = TYP_DIMSIZE;
- for (i=0;i<TYP_RANK;i++){
- stride[i]=1;
- start[i]=0;
- edges[i]=dims[i];
-
- }
-
- /* Open the HDF file. */
-
- file_id = Hopen(FILEHL, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open hdf file.\n");
- return FAIL;
- }
-
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vdata interface.\n");
- return FAIL;
- }
- vgroupa_ref = -1;
- vgroupb_ref = -1;
- vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach group a.\n");
- return FAIL;
- }
- vgroupb_id = Vattach(file_id, vgroupb_ref, "w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach groupb.\n");
- return FAIL;
- }
- istat = Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- istat = Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- sd_id = SDstart(FILEHL,DFACC_WRITE);
- if(sd_id == FAIL) {
- printf("fail to start sd interface.\n");
- return FAIL;
- }
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,TYP_RANK,dims);
- if(sds_id == FAIL) {
- printf("fail to create sds interface.\n");
- return FAIL;
- }
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("fail to write sds data.\n");
- return FAIL;
- }
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("fail to create sds reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupa_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add sds into vgroupa\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add sds into vgroupb\n");
- return FAIL;
- }
- SDendaccess(sds_id);
- SDend(sd_id);
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupb_id);
- istat = Vend(file_id);
- istat = Hclose(file_id);
- return 0;
-}
-/* this is a comprehensive testing file for h4-h5 converter. It includes
- annotation,vdata,image,sds,palette and vgroup objects*/
-/* the structure of the hdf5 file is as follows:
- root
- / \
- gc ga<--
- / \ |
- gd gb--
- /
- ge
-
- This file includes vdata,image and sds.
-
-*/
-int test_vgall() {
-
- typedef struct {
- float32 temp;
- int16 height;
- float32 speed;
- char ident;
- float32 position[2];
- } source_t;
-
- source_t source[NRECORDS];
-
- int32 file_id, vgroupa_ref, vgroupa_id,istat;
- int32 vgroupc_ref, vgroupc_id,vgroupb_ref,vgroupb_id;
- int32 vgroupd_ref, vgroupd_id,vgroupe_ref,vgroupe_id;
- int32 vdata_id,values[4]={32, 16, 32, 8};
-
- intn i, j,k;
-
- uint8 *databuf, *pntr;
- int bufsize, recsize;
- VOIDP fldbufpt[5];
-
- /*2. for sds */
- int32 sd_id,sds_id,dim_id;
- int32 sds_ref;
- int32 fill_value;
- int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 dimo_sca[TYP_DIMSIZE];
- int32 dim_sizes[TYP_RANK];
- int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
- float64 cal;
- float64 cal_err;
- float64 offset;
- float64 offset_err;
-
- /*3. for image. */
-
- int32 gr_id, ri_id, il,pal_id;
- int32 image_ncomp,image_data_type;
- int32 image_start[2], image_edges[2],image_dims[2];
- int16 image_data[Y_LENGTH][X_LENGTH][3];
- uint8 palette_data[NUM_COLORS*3];
- int32 image_num_comp;
- int32 image_num_entries;
- int32 image_ref;
-
- char* attr_value;
-
- /*4. for annotation. */
- int32 an_id,ann_id;
- int32 group_tag,group_ref;
-
- static char file_label[] = "This is a file label.";
- static char file_desc[] = "This is a file description.";
- static char data_label[] = "This is a data label.";
- static char data_desc[] = "This is a data description.";
-
- char label[] = "sds.label";
- char unit[] = "sds.unit";
- char format[] = "sds.format";
- char coordsys[] = "sds.coord";
-
- char dim_name0[] ="dim0";
- char dim_name1[] ="dim1";
- char dim_label[] ="dim.label";
- char dim_unit[] ="dim.unit";
- char dim_format[] ="dim.format";
-
- /**** initial setting. ****/
- cal = 1.0;
- cal_err = 0.0;
- offset = 0.0;
- offset_err = 0.0;
- fill_value = 999;
-
- attr_value = malloc(ATT_SIZE*sizeof(char));
- if(attr_value == NULL) {
- printf("fail to allocate memory.\n");
- return FAIL;
- }
- strcpy(attr_value,"test attr");
-
- for (i=0;i<TYP_DIMSIZE;i++){
- for(j=0;j<TYP_DIMSIZE;j++) {
- for(k=0;k<TYP_DIMSIZE;k++) {
- array_data[i][j][k]=i+j;
- }
- }
- }
-
- for (i=0;i<TYP_DIMSIZE;i++)
- dimo_sca[i]= 2*i;
-
- for (i=0;i<TYP_RANK;i++){
- stride[i]=1;
- start[i]=0;
- dim_sizes[i] = TYP_DIMSIZE;
- edges[i]=dim_sizes[i];
-
- }
-
- /* Open the HDF file. */
-
- file_id = Hopen(FILEVG, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open the file.\n");
- return FAIL;
- }
-
- /* create annotations. */
-
- /* Initialize the AN interface and obtain an interface id. */
- an_id = ANstart(file_id);
- if(an_id == FAIL) {
- printf("fail to start annotation interface.\n");
- return FAIL;
- }
- /* Create a file label and obtain an annotation id. */
- ann_id = ANcreatef(an_id, AN_FILE_LABEL);
- if(ann_id == FAIL) {
- printf("fail to create file annotion interface.\n");
- return FAIL;
- }
-
- /* Write the file label to the file. */
- istat = ANwriteann(ann_id, file_label, (int32)(strlen(file_label)));
- if(istat == FAIL) {
- printf("fail to write file annotation.\n");
- return FAIL;
- }
-
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Create a file description. */
- ann_id = ANcreatef(an_id, AN_FILE_DESC);
- if(ann_id == FAIL) {
- printf("fail to create file annotion interface.\n");
- return FAIL;
- }
- /* Write the file description to the file. */
- istat = ANwriteann(ann_id, file_desc, (int32)(strlen(file_desc)));
- if(istat == FAIL) {
- printf("fail to write file annotation.\n");
- return FAIL;
- }
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Initialize the Vset interface. */
-
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start vdata interface.\n");
- return FAIL;
- }
- /** Create Vgroup VA and VB***/
- vgroupa_ref = -1;
- vgroupb_ref = -1;
-
- /* Attach to the target vgroup. */
- vgroupa_id = Vattach(file_id, vgroupa_ref, "w");
- if(vgroupa_id == FAIL) {
- printf("fail to attach group a.\n");
- return FAIL;
- }
- istat=Vsetname(vgroupa_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupa.\n");
- return FAIL;
- }
- /* Attach an attribute to the vgroup. */
-
- istat = Vsetattr(vgroupa_id,"vgattr",DFNT_CHAR,5,"TESTa");
- if(istat == FAIL) {
- printf("fail to set attribute.\n");
- return FAIL;
- }
-
- vgroupb_id = Vattach(file_id,vgroupb_ref,"w");
- if(vgroupb_id == FAIL) {
- printf("fail to attach group b.\n");
- return FAIL;
- }
- Vsetname(vgroupb_id,"groupB");
- if(istat == FAIL) {
- printf("fail to set name for groupb.\n");
- return FAIL;
- }
- /* adding annotation into the file. */
- group_tag = VQuerytag(vgroupb_id);
- if(group_tag == FAIL) {
- printf("query groupb tag failed.\n");
- return FAIL;
- }
- group_ref = VQueryref(vgroupb_id);
- if(group_ref == FAIL) {
- printf("query groupb ref failed.\n");
- return FAIL;
- }
-
- /* Create a data label for the Vgroup just created. */
- ann_id = ANcreate(an_id, (uint16)group_tag,(uint16)group_ref, AN_DATA_LABEL);
- if(ann_id == FAIL) {
- printf("AN create interface failed.\n");
- return FAIL;
- }
-
- /* Write the data label to the file. */
- istat = ANwriteann(ann_id, data_label, (int32)(strlen(data_label)));
- if(istat == FAIL) {
- printf("fail to write annotation.\n");
- return FAIL;
- }
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Create a data description for the Vgroup just created.*/
- ann_id = ANcreate(an_id, (uint16)group_tag, (uint16)group_ref, AN_DATA_DESC);
- if(ann_id == FAIL) {
- printf("AN create interface failed.\n");
- return FAIL;
- }
- /* Write the data description to the file. */
- istat = ANwriteann(ann_id, data_desc, (int32)(strlen(data_desc)));
- if(istat == FAIL) {
- printf("fail to write annotation.\n");
- return FAIL;
- }
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Terminate access to the AN interface. */
- istat = ANend(an_id);
- /* end of annotations. */
-
- istat = Vsetattr(vgroupb_id, VGATTR_NAME, DFNT_CHAR, 5, "TESTb");
- if(istat == FAIL) {
- printf("fail to set attribute.\n");
- return FAIL;
- }
- istat = Vinsert(vgroupa_id,vgroupb_id);
- if(istat == FAIL) {
- printf("fail to insert groupb into groupa. \n");
- return FAIL;
- }
-
- vgroupc_ref = -1;
- vgroupd_ref = -1;
- vgroupe_ref = -1;
- vgroupc_id = Vattach(file_id,vgroupc_ref,"w");
- if(vgroupc_id == FAIL) {
- printf("fail to attach groupc into file.\n");
- return FAIL;
- }
-
- istat= Vsetname(vgroupc_id,"groupA");
- if(istat == FAIL) {
- printf("fail to set name for groupA.\n");
- return FAIL;
- }
-
- vgroupd_id = Vattach(file_id,vgroupd_ref,"w");
- if(vgroupd_id == FAIL) {
- printf("fail to attach groupd into the file.\n");
- return FAIL;
- }
-
- istat= Vsetname(vgroupd_id,"groupD");
- if(istat == FAIL) {
- printf("fail to set name for groupD.\n");
- return FAIL;
- }
- vgroupe_id = Vattach(file_id,vgroupe_ref,"w");
- if(vgroupe_id == FAIL) {
- printf("fail to attach groupe into the file.\n");
- return FAIL;
- }
- istat=Vsetname(vgroupe_id,"groupE");
- if(istat == FAIL) {
- printf("fail to set name for groupD.\n");
- return FAIL;
- }
- istat = Vinsert(vgroupc_id,vgroupd_id);
- if(istat == FAIL) {
- printf("fail to insert groupd into groupc.\n");
- return FAIL;
- }
-
- istat = Vinsert(vgroupd_id,vgroupe_id);
- if(istat == FAIL) {
- printf("fail to insert groupe into groupd.\n");
- return FAIL;
- }
- istat = Vinsert(vgroupe_id,vgroupc_id);
- if(istat == FAIL) {
- printf("fail to insert groupc into groupe.\n");
- return FAIL;
- }
- /* Create a new Vdata. */
-
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata.\n");
- return FAIL;
- }
- /* Define the field to write. */
-
- istat = VSfdefine(vdata_id, FIELD_1, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 1.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_2, DFNT_INT16, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 2.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_3, DFNT_FLOAT32, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 3.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_4, DFNT_CHAR8, 1);
- if(istat == FAIL) {
- printf("fail to define vdata field 4.\n");
- return FAIL;
- }
- istat = VSfdefine(vdata_id, FIELD_5, DFNT_FLOAT32,2);
- if(istat == FAIL) {
- printf("fail to define vdata field 5.\n");
- return FAIL;
- }
- /* Set the Vdata name. */
- istat = VSsetname(vdata_id, "Example Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
- /* Set the Vdata class. */
- istat = VSsetclass(vdata_id, "Example Vset Class");
- if(istat == FAIL) {
- printf("fail to set vdata class.\n");
- return FAIL;
- }
- /* Set the field names. */
- istat = VSsetfields(vdata_id, FIELD_NAMES);
- if(istat == FAIL) {
- printf("fail to set fields.\n");
- return FAIL;
- }
- recsize = (2 * sizeof(float32) + sizeof(int16)) +2* sizeof(float32)
- +sizeof(char);
- /********************debugging *********************/
- /* + sizeof(char)); */
-
- bufsize = recsize * NRECORDS;
-
- databuf = (uint8 *) malloc((size_t)bufsize);
-
- if (databuf == NULL) {
- printf("malloc failed\n");
- return FAIL;
- }
- pntr = databuf;
-
- /* set record values */
- for (i = 0; i < NRECORDS; i++) {
- source[i].temp = 1.11 * (i+1);
- source[i].height = i;
- source[i].speed = 1.11 * (i+1);
- source[i].ident = 'A' + i;
- for (j=0; j< 2; j++)
- source[i].position[j] = 1.0+j;
-
- }
-
- /* pack one record at a time */
- for (i = 0; i< NRECORDS; i++) {
- /* set field buf address */
- fldbufpt[0] = &source[i].temp;
- fldbufpt[1] = &source[i].height;
- fldbufpt[2] = &source[i].speed;
- fldbufpt[3] = &source[i].ident;
- fldbufpt[4] = &source[i].position[0];
- /* pack field data into databuf */
- istat = VSfpack(vdata_id,_HDF_VSPACK,NULL,(VOIDP)pntr,
- recsize, 1, NULL, fldbufpt);
- if (istat == FAIL) {
- printf("VSfpack failed in packing record %d\n", i);
- return FAIL;
- }
- pntr = pntr + recsize;
- }
-
- /* Write the data to the Vset object. */
- istat = VSwrite(vdata_id, databuf, NRECORDS, FULL_INTERLACE);
- if(istat == FAIL) {
- printf("fail to write vdata.\n");
- return FAIL;
- }
- /* Set Vdata attribute */
- istat = VSsetattr (vdata_id, _HDF_VDATA, "Fixed_type", DFNT_INT32, 4,
- (VOIDP)values);
- if(istat == FAIL) {
- printf("fail to set vdata attribute.\n");
- return FAIL;
- }
- /* Set attribute for "speed" field */
- istat = VSsetattr (vdata_id, 2, "Symbol", DFNT_CHAR, 3, "MAX");
- if(istat == FAIL) {
- printf("fail to set speed attribute.\n");
- return FAIL;
- }
-
- istat = VSdetach(vdata_id);
- if(istat == FAIL) {
- printf("fail to detach vdata.\n");
- return FAIL;
- }
-
- /*** initialize another empty vdata set to test name clashings ***/
-
- vdata_id = VSattach(file_id, -1, "w");
- if(vdata_id == FAIL) {
- printf("fail to attach vdata_id into file_id.\n");
- return FAIL;
- }
-
- /* Set the Vdata name. */
-
- istat = VSsetname(vdata_id, "Example Vset Name");
- if(istat == FAIL) {
- printf("fail to set vdata name.\n");
- return FAIL;
- }
- istat = VSdetach(vdata_id);
- if(istat == FAIL) {
- printf("fail to detach vdata.\n");
- return FAIL;
- }
-
- /* Initialize an independent Image interface. */
- /************************************************/
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
- image_ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- image_dims[0] = X_LENGTH;
- image_dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_1", image_ncomp, DFNT_INT16, il,
- image_dims);
- if(ri_id == FAIL) {
- printf("fail to create GR object.\n");
- return FAIL;
- }
-
- /* Fill the stored-data array with values. */
-
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data[j][i][0] = (i + j) + 1;
- image_data[j][i][1] = (i + j) + 1;
- image_data[j][i][2] =(i+j)+1;
- }
- }
-
- /* Define the location, pattern, and size of the data set */
-
- for (i = 0; i < 2; i++) {
- image_start[i] = 0;
- image_edges[i] = image_dims[i];
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
- (VOIDP)image_data);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Initialize the palette to grayscale. */
- for (i = 0; i < NUM_COLORS; i++) {
- palette_data[i * 3] = i;
- palette_data[i * 3 + 1] = i;
- palette_data[i * 3 + 2] = i;
- }
-
- /* Set palette characteristics. */
-
- image_data_type = DFNT_UINT8;
- image_num_entries = NUM_COLORS;
- image_num_comp = 3;
-
-
- /* Get the id for the palette. */
- pal_id = GRgetlutid(ri_id,0 );
- if(pal_id == FAIL) {
- printf("fail to get palette id.\n");
- return FAIL;
- }
-
- /* Write the palette to file. */
- istat = GRwritelut(pal_id, image_num_comp, image_data_type,
- 0, image_num_entries,(VOIDP)palette_data);
- if(istat == FAIL) {
- printf("fail to write palette.\n");
- return FAIL;
- }
- image_ref = GRidtoref(ri_id);
- if(image_ref == FAIL) {
- printf("fail to get reference of image.\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- istat = GRendaccess(ri_id);
-
- /* Terminate access to the GR interface. */
- istat = GRend(gr_id);
-
-
- /*** III. setting SDS data and all SDS attributes. ***/
-
- sd_id = SDstart(FILEVG,DFACC_WRITE);
-
- if (sd_id == FAIL){
- printf (" fail to open sd interface. \n");
- return FAIL;
- }
-
- istat = SDsetfillmode(sd_id,SD_NOFILL);
-
- if (istat == FAIL) {
- printf("error setting fill mode\n");
- return FAIL;
- }
- sds_id = SDcreate(sd_id,"sds",DFNT_INT32,3,dim_sizes);
- if(sds_id == FAIL) {
- printf("fail to create sds objects.\n");
- return FAIL;
- }
-
- istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
-
- if (istat == FAIL){
- printf("error setting fill value\n");
- return FAIL;
- }
-
- /*** 3.1 write data. ***/
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
-
- if(istat == FAIL) {
- printf(" sds data written failed. \n");
- return FAIL;
- }
- /*** 3.2 write dataset attribute ***/
-
- istat = SDsetattr(sds_id,"sds.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
- if(istat == FAIL) {
- printf(" sds data attr. setting failed. \n");
- return FAIL;
- }
- /*** 3.3 write dataset predefined attribute ***/
-
- istat = SDsetdatastrs(sds_id,label,unit,format,coordsys);
- if(istat == FAIL) {
- printf(" sds data predefined attr. setting failed. \n");
- return FAIL;
- }
- /*** 3.4 set calibration information. ***/
-
- istat = SDsetcal(sds_id,cal,cal_err,offset,offset_err,DFNT_INT32);
- if(istat == FAIL) {
- printf(" sds data calibrating attr. setting failed. \n");
- return FAIL;
- }
-
- /*** 3.5 write down dimension scale dataset. ***/
-
- for (i =0; i<TYP_RANK;i++) {
- dim_id = SDgetdimid(sds_id,i);
- if(dim_id <0) {
- printf("sds set dim id failed. \n");
- return FAIL;
- }
- if (i==0) {
- istat = SDsetdimname(dim_id,dim_name0);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat= SDsetdimscale(dim_id,dim_sizes[0],DFNT_INT32,(VOIDP)dimo_sca);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- }
- else {
- istat = SDsetdimname(dim_id,dim_name1);
- if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
- }
- istat = SDsetdimscale(dim_id,dim_sizes[1],DFNT_INT32,(VOIDP)dimo_sca);
- if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
- }
- }
-
- istat=SDsetdimstrs(dim_id,dim_label,dim_unit,dim_format);
- if(istat == FAIL) {
- printf("sds set dim. predefined attr. failed. \n");
- return FAIL;
- }
- istat = SDsetattr(dim_id,"sdsdim.attr",DFNT_CHAR8,10,(VOIDP)attr_value);
-
- if(istat == FAIL) {
- printf(" sds dim data attr. setting failed. \n");
- return FAIL;
- }
- SDendaccess(dim_id);
- }
-
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("fail to transfer id to reference.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupb_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add reference into vgroup.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
- SDend(sd_id);
-
- sd_id = SDstart(FILEVG,DFACC_WRITE);
-
- if (sd_id == FAIL){
- printf (" open file failed\n");
- return FAIL;
- }
- istat = SDsetfillmode(sd_id,SD_NOFILL);
-
- if (istat == FAIL){
- printf("error setting fill mode\n");
- return FAIL;
- }
- sds_id = SDcreate(sd_id,"sds2",DFNT_INT32,3,dim_sizes);
- if(sds_id == FAIL) {
- printf("fail to create sds id.\n");
- return FAIL;
- }
- istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
-
- if (istat == FAIL){
- printf("error setting fill value\n");
- return FAIL;
- }
- /*** 3.1 write data. ***/
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
- if(istat == FAIL) {
- printf("fail to write sds data.\n");
- return FAIL;
- }
-
- sds_ref = SDidtoref(sds_id);
- if(sds_ref == FAIL) {
- printf("fail to generate reference number.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupd_id,DFTAG_NDG,sds_ref);
- if(istat == FAIL) {
- printf("fail to add sds reference into groupd.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
- SDend(sd_id);
-
- sd_id = SDstart(FILEVG,DFACC_WRITE);
- if (sd_id == FAIL) {
- printf (" open file failed\n");
- return FAIL;
- }
-
- istat = SDsetfillmode(sd_id,SD_NOFILL);
-
- if (istat == FAIL) {
- printf("error setting fill mode. \n");
- return FAIL;
- }
-
- sds_id = SDcreate(sd_id,"sds2",DFNT_INT32,3,dim_sizes);
- if(sds_id == FAIL) {
- printf("error creating sds objects.\n");
- return FAIL;
- }
-
- istat = SDsetfillvalue(sds_id,(VOIDP)(&fill_value));
-
- if (istat == FAIL) {
- printf("error setting fill value\n");
- return FAIL;
- }
-
- /*** 3.1 write data. ***/
-
- istat = SDwritedata(sds_id,start,stride,edges,(VOIDP)array_data);
-
- if(istat == FAIL) {
- printf("error writing sds object.\n");
- return FAIL;
- }
-
- SDendaccess(sds_id);
- SDend(sd_id);
-
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("error starting gr interface.\n");
- return FAIL;
- }
-
- image_ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- image_dims[0] = X_LENGTH;
- image_dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_1", image_ncomp, DFNT_INT16, il,
- image_dims);
-
- if(ri_id == FAIL) {
- printf("fail to creat GR interface.\n");
- return FAIL;
- }
-
- /* Fill the stored-data array with values. */
-
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data[j][i][0] = (i + j) + 2;
- image_data[j][i][1] = (i + j) + 3;
- image_data[j][i][2] =(i+j)+1;
- }
- }
-
- /* Define the location, pattern, and size of the data set */
-
- for (i = 0; i < 2; i++) {
- image_start[i] = 0;
- image_edges[i] = image_dims[i];
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
- (VOIDP)image_data);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- /* Initialize the palette to grayscale. */
- for (i = 0; i < NUM_COLORS; i++) {
- palette_data[i * 3] = i;
- palette_data[i * 3 + 1] = i;
- palette_data[i * 3 + 2] = i;
- }
-
- /* Set palette characteristics. */
-
- image_data_type = DFNT_UINT8;
- image_num_entries = NUM_COLORS;
- image_num_comp = 3;
-
-
- /* Get the id for the palette. */
- pal_id = GRgetlutid(ri_id,0 );
-
- if(pal_id == FAIL) {
- printf("fail to get palette id.\n");
- return FAIL;
- }
-
- /* Write the palette to file. */
- istat = GRwritelut(pal_id, image_num_comp, image_data_type,
- 0, image_num_entries,(VOIDP)palette_data);
- if(istat == FAIL) {
- printf("fail to write palette data.\n");
- return FAIL;
- }
-
- image_ref = GRidtoref(ri_id);
- if(image_ref == FAIL) {
- printf("fail to obtain image reference number.\n");
- return FAIL;
- }
- istat = Vaddtagref(vgroupd_id,DFTAG_RIG,image_ref);
- if(istat == FAIL) {
- printf("fail to add image into group vgroupd\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- istat = GRendaccess(ri_id);
- if(istat == FAIL) {
- printf("fail to end GR interface.\n");
- return FAIL;
- }
-
- /* Terminate access to the GR interface. */
- istat = GRend(gr_id);
-
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("fail to start GR interface.\n");
- return FAIL;
- }
-
- image_ncomp = 3;
- il = MFGR_INTERLACE_PIXEL;
- image_dims[0] = X_LENGTH;
- image_dims[1] = Y_LENGTH;
-
- /* Create the array. */
- ri_id = GRcreate(gr_id, "Image_2", image_ncomp, DFNT_INT16, il,
- image_dims);
- if(ri_id == FAIL) {
- printf("fail to create GR interface.\n");
- return FAIL;
- }
-
- /* Fill the stored-data array with values. */
-
- for (j = 0; j < Y_LENGTH; j++) {
- for (i = 0; i < X_LENGTH; i++) {
- image_data[j][i][0] = (i + j) + 2;
- image_data[j][i][1] = (i + j) + 3;
- image_data[j][i][2] =(i+j)+1;
- }
- }
-
- /* Define the location, pattern, and size of the data set */
-
- for (i = 0; i < 2; i++) {
- image_start[i] = 0;
- image_edges[i] = image_dims[i];
- }
-
- /* Write the stored data to the image array. */
- istat = GRwriteimage(ri_id, image_start, NULL, image_edges,
- (VOIDP)image_data);
-
- if(istat == FAIL) {
- printf("fail to write image.\n");
- return FAIL;
- }
-
- /* Initialize the palette to grayscale. */
- for (i = 0; i < NUM_COLORS; i++) {
- palette_data[i * 3] = i;
- palette_data[i * 3 + 1] = i;
- palette_data[i * 3 + 2] = i;
- }
-
- /* Set palette characteristics. */
-
- image_data_type = DFNT_UINT8;
- image_num_entries = NUM_COLORS;
- image_num_comp = 3;
-
-
- /* Get the id for the palette. */
- pal_id = GRgetlutid(ri_id,0 );
- if(pal_id == FAIL) {
- printf("fail to obtain palette id.\n");
- return FAIL;
- }
-
- /* Write the palette to file. */
- istat = GRwritelut(pal_id, image_num_comp, image_data_type,
- 0, image_num_entries,(VOIDP)palette_data);
-
- if(istat == FAIL) {
- printf("fail to write GR image.\n");
- return FAIL;
- }
-
- image_ref = GRidtoref(ri_id);
- if(image_ref == FAIL) {
- printf("fail to generate image reference number.\n");
- return FAIL;
- }
-
- istat = Vaddtagref(vgroupa_id,DFTAG_RIG,image_ref);
- if(istat == FAIL) {
- printf("fail to add image into vgroupa\n");
- return FAIL;
- }
-
- /* Terminate access to the image. */
- istat = GRendaccess(ri_id);
-
- /* Terminate access to the GR interface. */
- istat = GRend(gr_id);
-
- istat =Vdetach(vgroupb_id);
- /* Detach from the vgroup, close the V interface and the file. */
- istat = Vdetach(vgroupa_id);
- istat = Vdetach(vgroupc_id);
- istat = Vdetach(vgroupd_id);
- istat = Vdetach(vgroupe_id);
- istat = Vend(file_id);
-
- istat = Hclose(file_id);
- return 0;
-}
-/* this routine creates annotation for four cases:
-
-1. file label
-2. file description
-3. object label(vgroup)
-4. object description(vgroup)
-
-*/
-
-int test_anno() {
-
- int32 file_id, an_id, ann_id, vgroup_id,istat;
- uint16 obj_tag, obj_ref;
- static char file_label[] = "This is a file label.";
- static char file_desc[] = "This is a file description.";
- static char data_labelvg[] = "This is a vgroup data label.";
- static char data_descvg[] = "This is a vgroup data description.";
-
- /* Create the HDF file. */
- file_id = Hopen(FILEANNO, DFACC_CREATE, 0);
- if(file_id == FAIL) {
- printf("fail to open HDF file \n");
- return FAIL;
- }
- /* Initialize the AN interface and obtain an interface id. */
- an_id = ANstart(file_id);
- if(an_id == FAIL) {
- printf("fail to start annotation interface.\n");
- return FAIL;
- }
-
- /* Create a file label and obtain an annotation id. */
- ann_id = ANcreatef(an_id, AN_FILE_LABEL);
- if(ann_id == FAIL) {
- printf("fail to create annotation id.\n");
- return FAIL;
- }
-
- /* Write the file label to the file. */
- istat = ANwriteann(ann_id, file_label, (int32)(strlen(file_label)));
- if(istat == FAIL) {
- printf("fail to write annotation.\n");
- return FAIL;
- }
-
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Create a file description. */
- ann_id = ANcreatef(an_id, AN_FILE_DESC);
- if(ann_id == FAIL) {
- printf("fail to create annotation\n");
- return FAIL;
- }
-
- /* Write the file description to the file. */
- istat = ANwriteann(ann_id, file_desc, (int32)(strlen(file_desc)));
- if(istat == FAIL) {
- printf("fail to write annotation.\n");
- return FAIL;
- }
-
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
-
- /* Create a vgroup. */
- istat = Vstart(file_id);
- if(istat == FAIL) {
- printf("fail to start v interface.\n");
- return FAIL;
- }
-
- vgroup_id = Vattach(file_id, -1, "w");
- if(vgroup_id == FAIL) {
- printf("fail to attach vgroup \n");
- return FAIL;
- }
-
- istat = Vsetname (vgroup_id, "Vgroup w/Annotations");
- if(istat == FAIL) {
- printf("fail to set group name\n");
- return FAIL;
- }
- /* Get reference number of vgroup just created. */
- obj_ref = Vfind (file_id, "Vgroup w/Annotations");
- if(obj_ref == 0) {
- printf("fail to set object reference.\n");
- return FAIL;
- }
- obj_tag = DFTAG_VG;
-
- /* Create a data label for the Vgroup just created. */
- ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_LABEL);
- if(ann_id == FAIL) {
- printf("fail to create annotation.\n");
- return FAIL;
- }
- /* Write the data label to the file. */
- istat = ANwriteann(ann_id, data_labelvg, (int)(strlen(data_labelvg)));
- if(istat == FAIL){
- printf("fail to write annotation.\n");
- return FAIL;
- }
- istat = ANendaccess(ann_id);
-
- obj_tag = DFTAG_VG;
-
- /* Create a data description for the Vgroup just created.*/
- ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_DESC);
- if(ann_id == FAIL) {
- printf("fail to create annotation.\n");
- return FAIL;
- }
-
- /* Write the data description to the file. */
- istat = ANwriteann(ann_id, data_descvg, (int)(strlen(data_descvg)));
- if(istat == FAIL) {
- printf("fail to write annotation.\n");
- return FAIL;
- }
- /* Terminate access to the annotation. */
- istat = ANendaccess(ann_id);
- istat = Vdetach(vgroup_id);
- istat = Vend(file_id);
- /* Close the file. */
-
- /* Terminate access to the AN interface. */
- istat = ANend(an_id);
- istat = Hclose(file_id);
- return 0;
-}
-
-
-
-
-
-
-
diff --git a/tools/h4toh5util.c b/tools/h4toh5util.c
deleted file mode 100644
index 879e8a9..0000000
--- a/tools/h4toh5util.c
+++ /dev/null
@@ -1,1633 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-including all routines that are useful for other files.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-
-#include "h4toh5util.h"
-
-
-/* Function h4toh5_ZeroMemory
- Purpose: Zero out memory
- return: None
- In: size_t n(DWORD in windows)
- void* s(PVOID in windows)
-*/
-void h4toh5_ZeroMemory(void*s,size_t n) {
-#ifdef WIN32
- ZeroMemory(s,n);
-#else
- bzero(s,n);
-#endif
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5string_to_int
- *
- * Purpose: This function will convert H5T_STRING into integer.
- This is a correction routine when the user define the
- numerical datatype int8 as DFNT_CHAR8 and DFNT_UCHAR8
-
- * Errors: will return error message to the interface
- * Return: FAIL if failed, SUCCEED if success
- *
- * In : h4type: HDF4 datatype
- h4memsize: the real memory size of h4type
-
- * Out: h5memtype: pointer of which value should be h5memtype(the real
- data type stored at the memory)
- h5type: pointer of which value should be h5type(the hdf5
- type stored at the disk).
- *
- *-------------------------------------------------------------------------
- */
-
-int h5string_to_int(const int32 h4type, hid_t* h5memtype,
- const size_t h4memsize,hid_t* h5type) {
-
- switch(h4type) {
-
- case DFNT_CHAR8:
-
- *h5type = H5T_STD_I8BE;
- if (h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_SCHAR;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_UCHAR8:
-
- *h5type = H5T_STD_U8BE;
- if (h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h4type_to_h5type
- *
- * Purpose: this function will convert HDF4 datatype into HDF5 datatype
- The converter includes file to file datatype and datasize
- conversion, file to memory datatype and datasize conversion.
- Check the mapping document for details.
-
- * Errors: will return error message to the interface.
- * Return: false, FAIL. otherwise,SUCCEED.
- *
- * In : h4type: HDF4 datatype.
- * Out: h4size: the file(disk) size of h4type.
- h4memsize: the real memory size of h4type.
- * h5memtype: pointer of which value should be h5memtype(the real
- type stored at the memory).
- h5type: pointer of which value should be h5type(the hdf5
- type that is stored at the disk).
- *
- *
- *-------------------------------------------------------------------------
- */
-int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
- size_t* h4memsize,size_t* h4size, hid_t *h5type)
-{
-
- switch (h4type) {
-
- case DFNT_CHAR8:
-
- *h4size = 1;
- *h4memsize = sizeof(int8);
- /* assume DFNT_CHAR8 C type character. */
- *h5memtype = H5T_STRING;
- *h5type = H5T_STRING;
- break;
-
- case DFNT_UCHAR8:
-
- *h4size = 1;
- *h4memsize = sizeof(int8);
- *h5memtype = H5T_STRING;
- *h5type = H5T_STRING;
- break;
-
- case DFNT_INT8:
-
- *h4size = 1;
- *h5type = H5T_STD_I8BE;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_SCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_UINT8:
-
- *h4size =1;
- *h5type = H5T_STD_U8BE;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_NINT8:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 1;
- *h5type = H5T_NATIVE_SCHAR;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_SCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_NUINT8:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 1;
- *h5type = H5T_NATIVE_UCHAR;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_LINT8:
- *h4size = 1;
- *h5type = H5T_STD_I8LE;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_LUINT8:
- *h4size = 1;
- *h5type = H5T_STD_U8LE;
- *h4memsize = sizeof(int8);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_INT16:
- *h4size = 2;
- *h5type = H5T_STD_I16BE;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_CHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_UINT16:
- *h4size = 2;
- *h5type = H5T_STD_U16BE;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_NINT16:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 2;
- *h5type = H5T_NATIVE_SHORT;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_CHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_NUINT16:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 2;
- *h5type = H5T_NATIVE_USHORT;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_LINT16:
- *h4size = 2;
- *h5type = H5T_STD_I16LE;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_LUINT16:
- *h4size = 2;
- *h5type = H5T_STD_U16LE;
- *h4memsize = sizeof(int16);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_INT32:
- *h4size = 4;
- *h5type = H5T_STD_I32BE;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_CHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_UINT32:
- *h4size = 4;
- *h5type = H5T_STD_U32BE;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_NINT32:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 4;
- *h5type = H5T_NATIVE_INT;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_CHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_NUINT32:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
- *h4size =4;
- *h5type = H5T_NATIVE_UINT;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_LINT32:
- *h4size =4;
- *h5type = H5T_STD_I32LE;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_CHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_SHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_INT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_LONG;
- else return FAIL;
- break;
-
- case DFNT_LUINT32:
- *h4size =4;
- *h5type = H5T_STD_U32LE;
- *h4memsize = sizeof(int32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_CHAR))
- *h5memtype = H5T_NATIVE_UCHAR;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_SHORT))
- *h5memtype = H5T_NATIVE_USHORT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_INT))
- *h5memtype = H5T_NATIVE_UINT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_LONG))
- *h5memtype = H5T_NATIVE_ULONG;
- else return FAIL;
- break;
-
- case DFNT_FLOAT32:
- *h4size =4;
- *h5type = H5T_IEEE_F32BE;
- *h4memsize = sizeof(float32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- case DFNT_FLOAT64:
- *h4size = 8;
- *h5type = H5T_IEEE_F64BE;
- *h4memsize = sizeof(float64);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- case DFNT_NFLOAT32:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
- *h4size = 4;
- *h5type = H5T_NATIVE_FLOAT;
- *h4memsize = sizeof(float32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- case DFNT_NFLOAT64:
- printf("warning, Native HDF datatype is encountered");
- printf(" the converting result may not be correct.\n");
- *h4size = 8;
- *h5type = H5T_NATIVE_DOUBLE;
- *h4memsize = sizeof(float64);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- case DFNT_LFLOAT32:
- *h4size = 4;
- *h5type = H5T_IEEE_F32LE;
- *h4memsize = sizeof(float32);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- case DFNT_LFLOAT64:
- *h4size = 8;
- *h5type = H5T_IEEE_F64LE;
- *h4memsize = sizeof(float64);
- if(*h4memsize == H5Tget_size(H5T_NATIVE_FLOAT))
- *h5memtype = H5T_NATIVE_FLOAT;
- else if(*h4memsize == H5Tget_size(H5T_NATIVE_DOUBLE))
- *h5memtype = H5T_NATIVE_DOUBLE;
- else return FAIL;
- break;
-
- default:
- return FAIL;
- }
- return SUCCEED;
-}
-/*-------------------------------------------------------------------------
- * Function: conv_int_str
- *
- * Purpose: this function will convert numerical number into the
- string format for a reference(<=65536).
- * Return: SUCCEED if success, FAIL if failed.
- *
- * In : num: an unsigned digital number that is not greater than 65536.
-
- * Out: str_num: character string format of the number.
-
- *
- *
- *-------------------------------------------------------------------------
- */
-
-int conv_int_str(uint16 num, char* str_num) {
-
- /* the maximum reference number is 65536. */
-
-
- if(str_num == NULL) {
- printf(" memory for str_num should be allocated.\n");
- return FAIL;
- }
-
- /* Adding this line will cause problems, investigating this later.
-h4toh5_ZeroMemory(str_num,strlen(str_num)+1);*/
-
- sprintf(str_num,"%d",num);
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: lookup
- *
- * Purpose: this function will use objref as a key to check whether
- * the current object is touched.
-
- * Return: 1, the object is found. 0,the object is not found.
- -1, the table doesn't exist.
- *
- * In : objref: reference number of the current object.
- SIZE: the hashtable SIZE.
- hashtab: pointer to the hash table.
-
- *-------------------------------------------------------------------------
- */
-
-int lookup(int objref,int SIZE,struct table*hashtab) {
-
- struct table *np;
- if(hashtab == NULL) {
- printf("the table doesn't exist. \n");
- return -1;
- }
- np = hashtab+objref%SIZE;
-
- for (np = hashtab+objref%SIZE; np!=NULL;np=np->next){
- if (np->ref == objref){
- return 1;
- }
- }
- return 0;
-}
-
-/*-------------------------------------------------------------------------
- * Function: init_tab
- *
- * Purpose: this function will initialize the hash table.
- *
-
- * Return: SUCCEED, table is initialzed. FAIL,otherwise.
- *
- * In :
- SIZE: the hashtable SIZE.
- hashtab: pointer to the hash table.
-
- *-------------------------------------------------------------------------
- */
-
-int init_tab(int SIZE,struct table *hashtab) {
-
- int i;
- if(hashtab == NULL) {
- printf("memory for hashing table is not allocated.\n");
- return FAIL;
- }
- for (i = 0;i < SIZE; i++) {
- (hashtab+i%SIZE)->ref = -1;
- (hashtab+i%SIZE)->next = NULL;
- (hashtab+i%SIZE)->name = NULL;
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: init_nametab
- *
- * Purpose: this function will initialize the name hash table.
- *
-
- * Return: SUCCEED, table is initialzed. FAIL,otherwise.
- *
- * In :
- SIZE: the hashtable SIZE.
- name_hashtab: pointer to the hash table.
-
- *-------------------------------------------------------------------------
- */
-int init_nametab(int SIZE, struct name_table * name_hashtab) {
-
- int i;
-
- if(name_hashtab == NULL) {
- printf("cannot allocate memory for name hashing table.\n");
- return FAIL;
- }
- for (i=0;i < SIZE; i++) {
- (name_hashtab+i%SIZE)->name = NULL;
- (name_hashtab+i%SIZE)->next = NULL;
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: get_name
- *
- * Purpose: obtain the name of the object
- *
- * Return: the object name
- *
- * In : objref: reference number of the current object.
- SIZE: the hashtable SIZE.
- hashtab: pointer to the hash table
- pcheck_get: a flag to check errors
-
- *-------------------------------------------------------------------------
- */
-
-char* get_name(int objref,int SIZE,struct table*hashtab, int* pcheck_get) {
-
- struct table *np;
- char* tempname;
-
- np = hashtab+objref%SIZE;
-
- for (np = hashtab+objref%SIZE; np!=NULL;np=np->next){
-
- if (np->ref==objref){
-
- if (np->name == NULL) {
- *pcheck_get = -1;
- return NULL;
- }
-
- else {
- tempname = malloc(strlen(np->name)+1);
- if(tempname == NULL) {
- *pcheck_get = -2;
- return NULL;
- }
- strcpy(tempname,np->name);
- return tempname;
- }
- }
- }
-
- *pcheck_get = 0;
- return NULL;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: set_name
- *
- * Purpose: store the name of the object into the hash table
- *
- * Return: SUCCEED: the name is either set before or set in this routine
- * FAIL: the name is not set properly
- *
- * In : objref: reference number of the current object
- SIZE: the hashtable SIZE
- hashtab: hash table
- namein: object name
-
- *-------------------------------------------------------------------------
- */
-
-
-int set_name(int objref,int SIZE,struct table*hashtab, char* namein) {
-
- struct table *np;
- struct table *temptr;
-
- temptr = malloc(sizeof(struct table));
- if(temptr == NULL) {
- printf("not enough memory to be allocated. \n");
- return FAIL;
- }
-
- np = hashtab+objref%SIZE;
- if(namein == NULL) {
- printf("error in inputting name into the table.\n");
- return FAIL;
- }
-
- for (np = hashtab+objref%SIZE; np!= NULL;np = np->next){
- if (np->ref==objref){
- /* the name is set already, don't do anything.*/
- return SUCCEED;
- }
- if (np->next == NULL) {
- np->next = temptr;
- temptr->ref = objref;
- temptr->next = NULL;
- temptr->name = malloc(strlen(namein)+1);
- if(temptr->name == NULL) {
- printf("error in allocating memory. \n");
- return FAIL;
- }
- strcpy(temptr->name,namein);
- return SUCCEED;
- }
- }
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: lookup_name
- *
- * Purpose: 1. look up whether the same name is used for different objects
- 2. then update the table
- *
- * Return: 1, if the name is in the name hash table.
- 0, if the name is to be added into the name table.
- -1, otherwise.
- *
- * In :
- size: the hashtable SIZE.
- nametab: name hash table
- name: the name to be looked up
-
- *-------------------------------------------------------------------------
- */
-
-int lookup_name(char* name, int size,struct name_table *nametab) {
-
- /* temporary pointer of the name table that points to the beginning
- address of the current bucket.*/
- struct name_table *np;
-
- /* temporary pointer of the added name table.*/
- struct name_table *temptr;
-
- if(name == NULL) {
- printf("the name to be looked up is NULL.\n");
- return -1;
- }
-
- temptr = malloc(sizeof(struct name_table));
- if(temptr == NULL) {
- printf("not enough memory to be allocated. \n");
- return -1;
- }
-
- if(nametab == NULL) {
- printf("no name_table for this category of objects.\n");
- return -1;
- }
- np = nametab+hash_fun(name,size);
-
- temptr->name = malloc(strlen(name)+1);
- if(temptr->name == NULL) {
- printf("not enough memory to be allocated to table name.\n");
- return -1;
- }
-
- /* look through the linked list starting from the current bucket.
- If the name is found, return 1, otherwise, return 0
- after inserting the new bucket. */
-
- for(np = nametab+hash_fun(name,size); np!= NULL;np = np->next) {
- if(np->name == NULL) {
- np->name = malloc(strlen(name)+1);
- if(np->name == NULL) {
- printf("cannot allocate memory for object name.\n");
- return -1;
- }
- strcpy(np->name,name);
- free(temptr->name);
- free(temptr);
- return 0;
- }
- if(strcmp(name,np->name)==0){
- free(temptr->name);
- free(temptr);
- return 1;
- }
- if (np->next == NULL) {
- np->next = temptr;
- temptr->next = NULL;
- strcpy(temptr->name,name);
- return 0;
- }
- }
- return -1;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: hash_fun
- *
- * Purpose: to get the hash value based on the key
- *
- * Return: No. of the hashtable
- *
- * In : name: object name
- size: the hashtable size.
-
- *-------------------------------------------------------------------------
- */
-int hash_fun(char *name,int size) {
-
-int hashval;
-
- for (hashval = 0;*name !='\0';)
- hashval += *name++;
- return(hashval%size);
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: freenametable
- *
- * Purpose: free the memory of hash table
- *
- * Return: 0
- *
- * In :
- SIZE: the hashtable SIZE.
- nametab: hash table of the name
-
- *-------------------------------------------------------------------------
- */
-int freenametable(int SIZE,struct name_table *nametab) {
-
- struct name_table *np,*temptr,*temptr1;
- int i;
-
- if(nametab == NULL) return 0;
- /* we first free the additional linked items of the hashtable,
- and then free the whole hash table. */
- for (i = 0;i < SIZE; i++) {
- np = nametab+i;
- temptr1 = np->next;
- while(temptr1 != NULL) {
- temptr = temptr1;
- temptr1 = temptr1->next;
- free(temptr->name);
- free(temptr);
- }
- if(np->name !=NULL) free(np->name);
- }
- free(nametab);
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: freetable
- *
- * Purpose: free the memory of hash table
- *
- * Return: 0
- *
- * In :
- SIZE: the hashtable SIZE.
- nametab: hash table
-
- *-------------------------------------------------------------------------
- */
-int freetable(int SIZE,struct table *hashtab) {
-
- struct table *np,*temptr,*temptr1;
- int i;
- if(hashtab == NULL) return 0;
-
- /* we first free the additional linked items of the hashtable,
- and then free the whole hash table. */
- for (i =0;i < SIZE; i++) {
- np = hashtab+i;
- temptr1 = np->next;
- while(temptr1 != NULL) {
- temptr = temptr1;
- temptr1 = temptr1->next;
- free(temptr->name);
- free(temptr);
- }
- if(np->name != NULL) free(np->name);
- }
-
- free(hashtab);
- return 0;
-}
-
-/*-------------------------------------------------------------------------
- * Function: mkstr
- *
- * Purpose: make hdf5 string type
- *
- * Return: type
- *
- * In :
- size: String Size
- H5T_str_t: pad
-
- *-------------------------------------------------------------------------
- */
-
-hid_t mkstr(int size, H5T_str_t pad) {
-
- hid_t type;
-
- if((type=H5Tcopy(H5T_C_S1))<0) return -1;
- if((H5Tset_size(type,(size_t)size))<0) return -1;
- if((H5Tset_strpad(type,pad))<0) return -1;
-
- return type;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h4_transnumattr
- *
- * Purpose: translate reference number into hdf5 attribute
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- h5g: hdf5 group id
- refname: reference name
- group_ref: reference number
-
- *-------------------------------------------------------------------------
- */
-int h4_transnumattr(hid_t h5g,const char *refname,uint16 group_ref) {
-
- hid_t h5memtype=(-1);
- hid_t h5a_id;
- hid_t h5a_sid;
- herr_t ret;
-
- h5a_sid = H5Screate(H5S_SCALAR);
-
- if (h5a_sid < 0) {
- fprintf(stderr,"failed to create attribute space for HDF4_REF_NUM. \n");
- return FAIL;
- }
-
- h5a_id = H5Acreate(h5g,refname,H5T_STD_U16BE,h5a_sid,H5P_DEFAULT);
-
- if(h5a_id <0) {
- fprintf(stderr,"failed to obtain attribute id for HDF4_REF_NUM. \n");
- H5Sclose(h5a_sid);
- return FAIL;
- }
-
- if(H5Tget_size(H5T_NATIVE_CHAR)== sizeof(uint16))
- h5memtype = H5T_NATIVE_UCHAR;
- else if(H5Tget_size(H5T_NATIVE_SHORT)== sizeof(uint16))
- h5memtype = H5T_NATIVE_USHORT;
- else if(H5Tget_size(H5T_NATIVE_INT) == sizeof(uint16))
- h5memtype = H5T_NATIVE_UINT;
- else if(H5Tget_size(H5T_NATIVE_LONG)== sizeof(uint16))
- h5memtype = H5T_NATIVE_ULONG;
-
- ret = H5Awrite(h5a_id,h5memtype,(void *)&group_ref);
-
- if(ret <0) {
- printf("failed to obtain attribute.\n ");
- H5Sclose(h5a_sid);
- H5Aclose(h5a_id);
- return FAIL;
- }
-
- ret = H5Sclose(h5a_sid);
- ret = H5Aclose(h5a_id);
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: h4_transpredattrs
- *
- * Purpose: translate predefined attributes into hdf5 attribute
- * predefined attributes include HDF4 OBJECT TYPE,
- HDF4 OBJECT NAME, HDF4 CLASS etc. They are all in
- H5T_STRING format.
-
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- h5g: group id
- attrname: attribute name
- data: attribute data
-
- *-------------------------------------------------------------------------
- */
-int h4_transpredattrs(hid_t h5g,const char *attrname,char*data){
-
- hsize_t h5str_size;
- hid_t h5a_id;
- hid_t h5a_sid;
- hid_t h5str_type;
- herr_t ret;
-
- if(data == NULL) {
- printf("attribute data is not available.\n");
- return FAIL;
- }
-
- h5str_size = strlen(data);
-
- if ((h5str_type = mkstr(h5str_size,H5T_STR_SPACEPAD))<0) {
- printf("error in making string for predefined ATTR. \n");
- return FAIL;
- }
-
- h5a_sid = H5Screate(H5S_SCALAR);
-
- if (h5a_sid < 0) {
- printf("failed to create attribute space for HDF4_OBJECT. \n");
- return FAIL;
- }
-
- h5a_id = H5Acreate(h5g,attrname,h5str_type,h5a_sid,H5P_DEFAULT);
-
- if(h5a_id <0) {
- fprintf(stderr,"failed to obtain attribute id for HDF4_OBJECT. \n");
- H5Sclose(h5a_sid);
- return FAIL;
- }
-
- ret = H5Awrite(h5a_id,h5str_type,(void *)data);
-
- if(ret <0) {
- fprintf(stderr,"failed to obtain attribute.\n ");
- H5Aclose(h5a_id);
- H5Sclose(h5a_sid);
- return FAIL;
- }
- ret = H5Sclose(h5a_sid);
- ret = H5Aclose(h5a_id);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: vg_transattrs
- *
- * Purpose: translate predefined vgroup attributes into hdf5 attribute
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- h4vg: hdf4 vgroup id
- h5g: hdf5 group id
-
- *-------------------------------------------------------------------------
- */
-
-int vg_transattrs(int32 h4vg,hid_t h5g) {
-
- /* define variables for hdf4. */
- char vgroup_name[VGNAMELENMAX];
- char vgroup_class[VGNAMELENMAX];
- char vgattr_name[MAX_NC_NAME];
- char obtype[MAX_NC_NAME];
-
- int32 vgroup_cref;
- int32 num_vgattr;
- int32 count_vgattr;
- int32 vg_atype;
- int32 attr_size;
-
- size_t sh4_size;
- size_t sh4_amemsize;
-
- /* define variables for hdf5. */
- hid_t sh5a_sid;
- hid_t sh5a_id;
- hid_t sh5_atype;
- hid_t sh5_amemtype;
- hid_t sh5str_type;
- hid_t sh5str_memtype;
- hsize_t sh5dims[MAX_VAR_DIMS];
- void* vg_adata;
- herr_t sret;
- int i;
-
- num_vgattr = Vnattrs(h4vg);
-
- for (i = 0;i <num_vgattr;i++) {
-
- if (Vattrinfo(h4vg,i,vgattr_name,&vg_atype,
- &count_vgattr,&attr_size)== FAIL){
- printf("unable to obtain attribute information. \n");
- return FAIL;
- }
-
- /* convert attribute datatype into the corresponding hdf5 datatype */
-
- if(h4type_to_h5type(vg_atype,&sh5_amemtype,&sh4_amemsize,
- &sh4_size,&sh5_atype)==FAIL){
- printf("unable to do data type converting.\n");
- return FAIL;
- }
-
- vg_adata = malloc(sh4_amemsize*count_vgattr);
-
- if(vg_adata == NULL) {
- printf("error in allocating vgroup attribute data. \n");
- return FAIL;
- }
-
- if(Vgetattr(h4vg,i,(VOIDP)vg_adata)==FAIL){
- printf("unable to get attribute.\n");
- free(vg_adata);
- return FAIL;
- }
-
- /* if the attribute doesn't have a name, a default name is set. */
- if(vgattr_name[0] == '\0')
- strcpy(vgattr_name,trans_obj_name(DFTAG_VG,i));
-
- /* now do attribute-transferring.
- 1. deal with string data type
- 2. set attribute space
- 3. get attribute name, set property list. */
-
- if (sh5_atype == H5T_STRING ) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space ");
- printf("for HDF4_OBJECT_TYPE SDS. \n");
- free(vg_adata);
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(count_vgattr*sh4_size,H5T_STR_SPACEPAD))<0) {
- fprintf(stderr,"error in making string for VGROUP ATTR. \n");
- free(vg_adata);
- return FAIL;
- }
-
-
- if ((sh5str_memtype = mkstr(count_vgattr*sh4_amemsize,
- H5T_STR_SPACEPAD))<0){
- fprintf(stderr,"error in making memory string for VGROUP ATTR. \n");
- free(vg_adata);
- return FAIL;
- }
-
- sh5a_id = H5Acreate(h5g,vgattr_name,sh5str_type,sh5a_sid,H5P_DEFAULT);
-
- if (sh5a_id <0) {
- printf("failed to obtain attribute id");
- printf(" for HDF4_OBJECT_TYPE VGROUP. \n");
- free(vg_adata);
- return FAIL;
- }
- sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)vg_adata);
-
- if (sret <0) {
- fprintf(stderr,"failed to obtain attribute.\n ");
- free(vg_adata);
- return FAIL;
- }
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
-
- else {
-
- if (count_vgattr == 1) {
- sh5a_sid = H5Screate(H5S_SCALAR);
- if (sh5a_sid < 0) {
- fprintf(stderr,"failed to create space id. \n");
- free(vg_adata);
- return FAIL;
- }
- }
-
- else {
-
- sh5dims[0] = count_vgattr;
- sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
- if (sh5a_sid < 0) {
- fprintf(stderr,"failed to create vgroup attribute space. \n");
- free(vg_adata);
- return FAIL;
- }
- }
-
- sh5a_id = H5Acreate(h5g,vgattr_name,sh5_atype,sh5a_sid,H5P_DEFAULT);
-
- if(sh5a_id <0) {
- fprintf(stderr,"failed to obtain attribute id. \n");
- free(vg_adata);
- H5Sclose(sh5a_sid);
- return FAIL;
- }
- sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)vg_adata);
-
- if(sret < 0) {
- fprintf(stderr,"failed to obtain attribute.\n ");
- free(vg_adata);
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- return FAIL;
- }
-
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
- free(vg_adata);
- }
-
- /*** check this line later. ***/
- strcpy(obtype,VGROUPLABEL);
- vgroup_class[0] = '\0';
-
- /* ignore CDF0.0 and RIG0.0 vgroups. */
- if(Vgetclass(h4vg,vgroup_class) == SUCCEED){
- if(vgroup_class[0] != '\0') {
- if(!strcmp(vgroup_class,_HDF_CDF)||
- !strcmp(vgroup_class,GR_NAME))
- return SUCCEED;
- }
- }
-
- /* transfer predefined attributes. */
- if(h4_transpredattrs(h5g,HDF4_OBJECT_TYPE,obtype)==FAIL){
- printf("error in data attribute transferring.\n");
- return FAIL;
- }
-
- if(Vgetname(h4vg,vgroup_name) == SUCCEED){
- if(vgroup_name[0] != '\0') {
- if(h4_transpredattrs(h5g,HDF4_OBJECT_NAME,vgroup_name)==FAIL){
- printf("error in data attribute transferring.\n");
- return FAIL;
- }
- }
- }
-
- if(vgroup_class[0] !='\0') {
- if(h4_transpredattrs(h5g,HDF4_VGROUP_CLASS,vgroup_class)==FAIL){
- printf("error in data attribute transferring.\n");
- return FAIL;
- }
- }
-
- vgroup_cref = VQueryref(h4vg);
- if(vgroup_cref == FAIL) {
- printf("failed to obtain group reference number.\n");
- return FAIL;
- }
-
- if(h4_transnumattr(h5g,HDF4_REF_NUM,vgroup_cref)==FAIL){
- printf("error in data attribute transferring.\n");
- return FAIL;
- }
-
- return SUCCEED;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: get_obj_aboname
- *
- * Purpose: get absolute path name of hdf5 object
- In this function, we will deal with name clashing.
- If we find an object name(by using lookup_name routine)
- that has already been used,
- we will remake name for this object. We will follow
- object type(vgroup,sds,image,palette, vdata) plus reference
- number to make it unique.
- *
- * Return: NULL if failed, object name if successful.
- *
- * In :
- obj_name: relative object name
- ref_str: reference number in character format
- path_name: absolute path
- objstr: object type in character format
-
- *-------------------------------------------------------------------------
- */
-
-char* get_obj_aboname(char* obj_name,char* refstr,char* path_name,
- const char*objstr ) {
-
- char *abo_objname;
- int check_name;
- char check_char;
-
-
- /* sometimes although the object name is not NULL, but it is empty.
- We will use make_objname_no under this situation. */
- if(obj_name != NULL) check_char = *obj_name;
-
- /* obtain the absolute name of the object. */
- if (obj_name == NULL || check_char == '\0')
- abo_objname = make_objname_no(refstr,path_name,objstr);
- else
- abo_objname = make_objname_yes(obj_name,path_name);
-
- /* look up the name and see whether there is name clashing here.
- if yes, remake the object name.*/
- check_name = lookup_name(abo_objname,num_objects,name_hashtab);
-
- if(check_name == 1) {
- /* name_clashing is found. */
- if(objstr != NULL && refstr != NULL){
- free(abo_objname);
-
- if(path_name != NULL) {
- abo_objname= malloc(strlen(path_name)+strlen(objstr)+
- strlen(refstr)+3);
- if(abo_objname == NULL) {
- printf("error in allocating memory. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(abo_objname,strlen(path_name)+strlen(objstr)+
- strlen(refstr)+3);
- strcpy(abo_objname,path_name);
- strcat(abo_objname,"/");
- strcat(abo_objname,objstr);
- strcat(abo_objname,"_");
- strcat(abo_objname,refstr);
- }
-
- else {
- abo_objname= malloc(strlen(objstr)+strlen(refstr)+3);
- if(abo_objname == NULL) {
- printf("error in allocating memory. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(abo_objname,strlen(objstr)+strlen(refstr)+3);
- strcat(abo_objname,"/");
- strcat(abo_objname,objstr);
- strcat(abo_objname,"_");
- strcat(abo_objname,refstr);
- }
- }
- }
-
- return abo_objname;
-}
-
-/*-------------------------------------------------------------------------
- * Function: make_objname_no
- *
- * Purpose: get absolute path name of hdf5 object when object name is
- not defined.
- We will use path name and
- object type(vgroup,sds,image,palette, vdata) plus reference
- number to make it unique.
- *
- * Return: NULL if failed, object name if successful.
- *
- * In :
- ref_str: reference number in character format
- path_name: absolute path
- objstr: object type in character format
-
- *-------------------------------------------------------------------------
- */
-
-char* make_objname_no(char* refstr,char* path_name,const char*objstr) {
-
- char *new_objname;
-
- if(objstr == NULL || refstr == NULL) {
- printf("error, object type and ref. number should be defined.\n");
- return NULL;
- }
-
- if (path_name == NULL) {/* under root group. */
-
- new_objname= malloc(strlen(objstr)+strlen(refstr)+3);
- if(new_objname == NULL) {
- printf("error in allocating memory for object name. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(new_objname,strlen(objstr)+strlen(refstr)+3);
- strcpy(new_objname,"/");
- strcat(new_objname,objstr);
- strcat(new_objname,"_");
- strcat(new_objname,refstr);
- }
-
- else {
-
- new_objname= malloc(strlen(path_name)+strlen(objstr)+strlen(refstr)+3);
- if(new_objname == NULL) {
- printf("error in allocating memory. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(new_objname,strlen(path_name)+strlen(objstr)+strlen(refstr)+3);
- strcpy(new_objname,path_name);
- strcat(new_objname,"/");
- strcat(new_objname,objstr);
- strcat(new_objname,"_");
- strcat(new_objname,refstr);
- }
-
- return new_objname;
-}
-
-/*-------------------------------------------------------------------------
- * Function: make_objname_yes
- *
- * Purpose: get absolute path name of hdf5 object when object name is
- defined.
-
- *
- * Return: NULL if failed, object name if successful.
- *
- * In : obj_name: object name
- path_name: absolute path
-
- *-------------------------------------------------------------------------
- */
-
-char* make_objname_yes(char* obj_name,char* path_name){
-
- char*new_objname;
-
- if(path_name == NULL) {
- new_objname = malloc(strlen(obj_name)+2);
- if(new_objname == NULL) {
- printf("error in allocating memory. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(new_objname,strlen(obj_name)+2);
- strcpy(new_objname,"/");
- strcat(new_objname,obj_name);
- }
- else {
- new_objname = malloc(strlen(path_name)+strlen(obj_name)+2);
- if(new_objname == NULL) {
- printf("error in allocating memory. \n");
- return NULL;
- }
- h4toh5_ZeroMemory(new_objname,strlen(path_name)+strlen(obj_name)+2);
- strcpy(new_objname,path_name);
- strcat(new_objname,"/");
- strcat(new_objname,obj_name);
- }
- return new_objname;
-}
-
-/*-------------------------------------------------------------------------
- * Function: trans_obj_name
- *
- * Purpose: obtain hdf4 attribute name from hdf4 object type
- plus ATTR plus reference number.
- *
- * Return: object name;
- *
- * In :
- obj_tag: hdf4 tag
- index : hdf5 group id
-
- *-------------------------------------------------------------------------
- */
-char* trans_obj_name(int32 obj_tag,int32 index) {
-
- char* obj_name;
- char indstr[5];
-
- /* the reason why we allocate memory with strlen(HDF4_PALETTE) is
- HDF4_PALETTE is the longest string among HDF4_??? */
- obj_name = malloc(strlen(HDF4_PALETTE)+strlen(ATTR)+8);
- if(obj_name == NULL) {
- printf("cannot allocate memory for object name. \n");
- return NULL;
- }
-
- h4toh5_ZeroMemory(obj_name,strlen(HDF4_PALETTE)+strlen(ATTR)+8);
-
- if(conv_int_str(index,indstr)== FAIL) {
- printf("indstr is not allocated. \n");
- return NULL;
- }
-
- switch(obj_tag) {
-
- case DFTAG_SD:
- case DFTAG_NDG:
- case DFTAG_SDG:
- strcpy(obj_name,HDF4_SDS);
- break;
-
- case DFTAG_RIG:
- case DFTAG_RI:
- case DFTAG_RI8:
- strcpy(obj_name,HDF4_IMAGE);
- break;
-
- case DFTAG_VG:
- strcpy(obj_name,HDF4_VGROUP);
- break;
-
- case DFTAG_VH:
- case DFTAG_VS:
- strcpy(obj_name,HDF4_VDATA);
- break;
-
- case DFTAG_LUT:
- strcpy(obj_name,HDF4_PALETTE);
- break;
-
- default:
- printf("error, object tag is transferred out of limits. \n");
- free(obj_name);
- return NULL;
- }
-
- strcat(obj_name,"_");
- strcat(obj_name,ATTR);
- strcat(obj_name,"_");
- strcat(obj_name,indstr);
-
- return obj_name;
-}
-/*-------------------------------------------------------------------------
- * Function: freehashmemory
- *
- * Purpose: free memories allocated for hash tables.
-
- *
- * Return: NULL
- *
- * In :
-
-
- *-------------------------------------------------------------------------
- */
-
-void freehashmemory(void){
-
- if(estnum_vg > 0) freetable(estnum_vg,vg_hashtab);
- if(estnum_vd > 0) freetable(estnum_vd,vd_hashtab);
-
- if(num_sds > 0) {
- freetable(2*num_sds,sds_hashtab);
- freenametable(DIM_HASHSIZE,dim_hashtab);
- }
-
- if(num_images > 0) {
- freetable(2*num_images,gr_hashtab);
- freetable(PAL_HASHSIZE,pal_hashtab);
- }
-
- if(num_objects > 0) freenametable(num_objects,name_hashtab);
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: correct_name
- *
- * Purpose: modify the hdf4 object name when the name contains '/'. Change
- this character into '_'.
-
- *
- * Return: the corrected name
- *
- * In : old name
-
-
- *-------------------------------------------------------------------------
- */
-char *correct_name(char* oldname){
-
- char * cptr;
- char * newname;
-
- if(oldname == NULL) {
- printf("inputting name is wrong.\n");
- return NULL;
- }
-
- newname = malloc(strlen(oldname)+1);
- h4toh5_ZeroMemory(newname,strlen(oldname)+1);
- newname = strncpy(newname, oldname, strlen(oldname));
-
- while(strchr(newname,ORI_SLASH)!= NULL){
- cptr = strchr(newname,ORI_SLASH);
- *cptr = CHA_SLASH;
- }
-
- return newname;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/h4toh5util.h b/tools/h4toh5util.h
deleted file mode 100644
index 7e3def7..0000000
--- a/tools/h4toh5util.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-Including declarations of global variables,global hashtables,constant
-and utility subroutines of h4toh5util.c
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-
-#ifndef UTILITY_H
-#define UTILITY_H
-#include "hdf5.h"
-#include "hdf.h"
-
-/**********************************************/
-/*************** section I *******************/
-/*This section of the file describes reserved
-name and global parameters used in h4-h5
-converter.*/
-/*********************************************/
-
-/* 0. if "/" is found in hdf4 object name, we will use another
- character "_" to replace it, since "/" is a reserved symbol for hdf5. */
-
-#define ORI_SLASH '/'
-#define CHA_SLASH '_'
-
-/* 1. character string used for default attribute name. */
-#define ATTR "ATTR"
-
-/* 2. Predefined HDF5 Attribute name for HDF4 file */
-
-#define HDF4_OBJECT_NAME "HDF4_OBJECT_NAME"
-#define HDF4_OBJECT_TYPE "HDF4_OBJECT_TYPE"
-#define HDF4_REF_NUM "HDF4_REF_NUM"
-#define HDF4_VGROUP_CLASS "HDF4_VGROUP_CLASS"
-#define HDF4_IMAGE_CLASS "CLASS"
-#define HDF4_IMAGE_SUBCLASS "IMAGE_SUBCLASS"
-#define HDF4_PALETTE_CLASS "CLASS"
-#define HDF4_PALETTE_TYPE "PAL_TYPE"
-#define PAL_TYPE "STANDARD8"
-#define PAL_COLORMODEL "PAL_COLORMODEL"
-#define RGB "RGB"
-/* 3. reserved name for HDF5 object name when meeting with name clashing. */
-
-#define HDF4_VGROUP "HDF4_VGROUP"
-#define HDF4_PALETTE "HDF4_PALETTE"
-#define HDF4_SDS "HDF4_SDS"
-#define HDF4_VDATA "HDF4_VDATA"
-#define HDF4_IMAGE "HDF4_IMAGE"
-#define HDF4_DIMSCALE "HDF4_DIMSCALE"
-
-/* 4. global palette and dimension_list name. */
-#define HDF4_IMAGE_PALETTE "HDF4_IMAGE_PALETTE"
-#define HDF4_DIMENSION_LIST "HDF4_DIMENSION_LIST"
-#define PALETTE "PALETTE"
-
-#define DIMSCALE "DIMSCALE"
-
-/* 5. define affix GLO for sds and image file attributes. these file attributes
- will be put under root group. */
-#define GLOSDS "GLOSDS"
-#define GLOIMAGE "GLOIMAGE"
-
-/* 6. define HDF object label.*/
-#define SDSLABEL "SDS"
-#define VDATALABEL "Vdata"
-#define VGROUPLABEL "Vgroup"
-#define GRLABEL "GR"
-#define RAST8LABEL "raster8"
-#define RAST24LABEL "raster24"
-#define PALABEL "palette"
-
-/* 7. define "IMAGE" CLASS required by image spec. */
-#define IM_CLASS "IMAGE"
-
-/* 8. reserved group name for HDF4 dimensional scale and palette. */
-#define HDF4_DIMG "/HDF4_DIMGROUP"
-#define HDF4_PALG "/HDF4_PALGROUP"
-
-/* 9. reserved name for hdf4 file label,file description, object label,
- object description. */
-#define HDF4_FILE_LABEL "HDF4_FILE_LABEL"
-#define HDF4_FILE_DESC "HDF4_FILE_DESCRIPTION"
-#define HDF4_OBJECT_LABEL "HDF4_OBJECT_LABEL"
-#define HDF4_OBJECT_DESC "HDF4_OBJECT_DESCRIPTION"
-#define HDF4_SDS_LABEL "HDF4_SDS_LABEL"
-#define HDF4_SDS_DESC "HDF4_SDS_DESC"
-#define HDF4_IMAGE_LABEL "HDF4_IMAGE_LABEL"
-#define HDF4_IMAGE_DESC "HDF4_IMAGE_DESC"
-#define HDF4_VDATA_LABEL "HDF4_VDATA_LABEL"
-#define HDF4_VDATA_DESC "HDF4_VDATA_DESC"
-#define HDF4_VGROUP_LABEL "HDF4_VGROUP_LABEL"
-#define HDF4_VGROUP_DESC "HDF4_VGROUP_DESC"
-#define HDF4_PAL_LABEL "HDF4_PAL_LABEL"
-#define HDF4_PAL_DESC "HDF4_PAL_DESC"
-#define HDF4_IMAGE_INDEXED "HDF4_IMAGE_INDEXED"
-
-/*10. palette and dimensional scale hash size and the
- maximum length of object reference number in string format.
- global variables of vgroup, vdata, sds, image and total number of
- the object, number of global sds attributes and GR attributes.*/
-
-#define PAL_HASHSIZE 64
-#define DIM_HASHSIZE 64
-#define VG_DEFHASHSIZE 64
-#define VD_DEFHASHSIZE 64
-#define MAXREF_LENGTH 5
-/*considering the string size of HDF4_DIMGROUP. we add this into 276.*/
-#define MAX_DIM_NAME 276
-#define MAX_PAL_NAME 32
-/*11. adding a specified vdata class name to deal with the situation when
-independent vdata is hdf chunking table _HDF_CHK_TBL_CLASS, if it becomes
-public constant for hdf lib, this constant can be released.*/
-#define _HDF_CHK_TBL_CLASS "_HDF_CHK_TBL_"
-
-extern int32 estnum_vg;
-extern int32 estnum_vd;
-extern int32 num_sds;
-extern int32 num_images;
-extern int num_objects;
-extern int32 num_glsdsattrs;
-extern int32 num_glgrattrs;
-
-/**********************************************/
-/*************** section II *******************/
-/*This section describes hash tables and their
- functions used in h4-h5 converter.*/
-/*********************************************/
-/*define two kinds of hashtables.
- 1. struct table uses object reference as the key to handle whether this
- object is visited or not.
- 2. struct name_table uses object name as the key to handle name clashings and
- dimensional scale dataset.
-*/
-
-struct table {
- int ref;
- struct table *next;
- char *name;
-};
-
-struct name_table {
- char *name;
- struct name_table *next;
-};
-
-extern struct table* sds_hashtab;
-extern struct table* gr_hashtab;
-extern struct table* vg_hashtab;
-extern struct table* vd_hashtab;
-extern struct table* pal_hashtab;
-extern struct name_table* name_hashtab;
-extern struct name_table* dim_hashtab;
-
-/* routine for zeroing out the memory. */
-void h4toh5_ZeroMemory(void*s,size_t n);
-
-/* look-up table, object reference is the key.*/
-int lookup(int,int,struct table*);
-
-/*look-up table, key is name. */
-int hash_fun(char*name,int size);
-int lookup_name(char*, int,struct name_table*);
-
-/* routines that initialize the tables and name tables.*/
-int init_tab(int,struct table*);
-int init_nametab(int,struct name_table*);
-
-/* get name and set name for table. */
-char* get_name(int,int,struct table *,int*);
-int set_name(int,int,struct table *,char*);
-
-/* free table routines. */
-int freetable(int,struct table *);
-int freenametable(int, struct name_table*);
-void freehashmemory(void);
-
-/**********************************************/
-/*************** section III *******************/
-/*This section describes other common routines and their
- functions used in h4-h5 converter.*/
-/*********************************************/
-
-/* this routine defines the conversion of data type from h4 to h5. */
-herr_t h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
- size_t* h4memsize, size_t* h4size, hid_t *h5type);
-
-/* routines for translating predefined hdf4 attributes into hdf5 attributes*/
-int h4_transpredattrs(hid_t ,const char *,char*data);
-int h4_transnumattr(hid_t h5g,const char *,uint16 group_ref);
-int vg_transattrs(int32,hid_t);
-
-/*string and int conversion routines.*/
-hid_t mkstr(int size, H5T_str_t pad);
-herr_t h5string_to_int(const int32, hid_t*,const size_t,hid_t* );
-int conv_int_str(uint16, char*);
-
-/* these routines were utility functions for other routines at h4toh5util.c */
-char* trans_obj_name(int32,int32);
-char* get_obj_aboname(char*,char*,char*,const char*);
-char* make_objname_no(char*,char*,const char*);
-char* make_objname_yes(char*,char*);
-char* correct_name(char*);
-
-#endif
-
-
-
-
diff --git a/tools/h4toh5vdata.c b/tools/h4toh5vdata.c
deleted file mode 100644
index 55a8bf9..0000000
--- a/tools/h4toh5vdata.c
+++ /dev/null
@@ -1,831 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-Converting an hdf4 independent vdata object into an hdf5 dataset of compound dataset.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-#include "h4toh5main.h"
-#include <assert.h>
-
-/*-------------------------------------------------------------------------
- * Function: Vdata_h4_to_h5
- *
- * Purpose: translate Vdata object into hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- vdata_id: RI identifier
- group_id: hdf5 group id
- Out:
-
- Modification:
- *-------------------------------------------------------------------------
- */
-
-int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
-
- /* define variables for hdf4. */
-
- int32 istat;
- int32 n_records;
-
- int32 vdata_ref;
- int32 vdata_tag;
-
- int32 interlace_mode;
-
- int32 vdata_size;
- int32 vdatamem_size;
-
- int32 field_index;
- int32 fieldorder;
- int32 fieldtype;
-
- int i;
- int32 nfields;
- int num_vd_attrs;
- int num_vd_field_attrs;
-
- VOIDP vd_data;
-
- char vdlabel[10];
- char vdata_name[MAX_NC_NAME];
- char fieldname[MAX_NC_NAME];
- char vdata_class[VSNAMELENMAX];
- char field_name_list[VSFIELDMAX*FIELDNAMELENMAX];
-
- /* define varibles for hdf5. */
-
- hid_t h5d_sid;
- hid_t h5dset;
-
- hid_t h5_ctype;
- hid_t h5_cmemtype;
-
- hid_t* h5memtype = NULL;
- hid_t* h5type = NULL;
-
- size_t* h4memsize = NULL;
- size_t* h4size = NULL;
- hsize_t h5_vddims[1];
- char* h5cvdata_name;
-
- int check_vdname;
-
- /* Zeroing out memory for vdlabel,vdata_class,vdata_name */
-
- h4toh5_ZeroMemory(vdata_name,MAX_NC_NAME);
- h4toh5_ZeroMemory(fieldname,MAX_NC_NAME);
- h4toh5_ZeroMemory(vdata_class,VSNAMELENMAX);
- h4toh5_ZeroMemory(field_name_list,VSFIELDMAX*FIELDNAMELENMAX);
- h4toh5_ZeroMemory(vdlabel,10);
-
- /* get absolute path of vdata name. */
-
- vdata_ref = VSQueryref(vdata_id);
- if (vdata_ref == FAIL) {
- printf("error in getting reference number. \n");
- return FAIL;
- }
-
- vdata_tag = VSQuerytag(vdata_id);
- if (vdata_tag == FAIL) {
- printf("error in getting object tag number. \n");
- return FAIL;
- }
-
- /* get the class name */
-
- if(VSgetclass(vdata_id,vdata_class) == FAIL) {
- printf("error in obtaining class name. \n");
- return FAIL;
- }
-
- /* get number of record,field_name,Size of a record and
- Name of the vdata*/
-
- if(VSQueryvsize(vdata_id,&vdata_size)==FAIL) {
- printf("error in getting size of vdata. \n");
- return FAIL;
- }
-
- if(vdata_size == 0) {/* empty vdata set. */
- return SUCCEED;
- }
-
- /* obtain number of records, field name list, vdata name. */
- if(VSinquire(vdata_id,&n_records,&interlace_mode,
- field_name_list,&vdata_size,vdata_name) == FAIL) {
- printf("error in inquiring vdata. \n");
- return FAIL;
- }
-
- vdatamem_size = 0;
- vdata_size = 0;
- nfields = VFnfields(vdata_id);
-
- if (nfields == FAIL) {
- printf("error in obtaining number of vdata fields. \n");
- return FAIL;
- }
-
- assert(nfields>0);
- h5memtype = calloc((size_t)nfields,sizeof(hid_t));
- h5type = calloc((size_t)nfields,sizeof(hid_t));
- h4memsize = calloc((size_t)nfields,sizeof(size_t));
- h4size = calloc((size_t)nfields,sizeof(size_t));
-
- for (i=0;i<nfields;i++) {
-
- /* obtain field type. */
- fieldtype = VFfieldtype(vdata_id,i);
- if(fieldtype == FAIL){
- printf("error in obtaining field type. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- return FAIL;
- }
-
- /* obtain field order.*/
- fieldorder = VFfieldorder(vdata_id,i);
- /* printf("fieldorder %d\n",fieldorder);*/
- if(fieldorder == FAIL){
- printf("error in obtaining field order. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- return FAIL;
- }
-
- /* datatype conversion from hdf4 to hdf5.
- the corresponding memory data type is also converted.*/
- if(h4type_to_h5type(fieldtype,&h5memtype[i],&h4memsize[i],
- &h4size[i],&h5type[i])== FAIL){
- printf("error in doing datatype conversion at vdata routine. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- return FAIL;
- }
-
- vdatamem_size +=fieldorder*h4memsize[i];
- vdata_size +=fieldorder*h4size[i];
-
- }
-
- vd_data = malloc((size_t)(vdatamem_size*n_records));
-
- istat = VSsetfields(vdata_id,field_name_list);
-
- if(istat == FAIL) {
- printf("error setting fields of vdata.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- istat = VSread(vdata_id,(uint8*)vd_data,n_records,FULL_INTERLACE);
-
- if(istat == FAIL) {
- printf("error in obtaining vdata. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- for (i=0;i<nfields;i++) {
- /* obtain field order.*/
- fieldorder = VFfieldorder(vdata_id,i);
-
- if(fieldorder == FAIL){
- printf("error in obtaining field order. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- return FAIL;
- }
- }
- /* create hdf5 compound datatype for both memory and file.*/
-
- h5_ctype = H5Tcreate(H5T_COMPOUND, (size_t)vdata_size);
- h5_cmemtype = H5Tcreate(H5T_COMPOUND,(size_t)vdatamem_size);
-
- if(gen_h5comptype(vdata_id,nfields,h4size,h4memsize,h5type,h5memtype,
- h5_ctype,h5_cmemtype)==FAIL){
- printf("error in generating h5 compound data type.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- h5_vddims[0] = n_records;
- h5d_sid = H5Screate_simple(1,h5_vddims,NULL);
-
- if(h5d_sid <0){
- printf("error in obtaining space id.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- /* choose a number that is not returned from the func.*/
- check_vdname = -3;
-
- /* obtain hdf5 vdata name. */
- h5cvdata_name = get_name(vdata_ref,estnum_vd,vd_hashtab,&check_vdname);
-
- if (h5cvdata_name == NULL && check_vdname == 0 ) {
- printf("error,cannot find vdata \n");
- return FAIL;
- }
-
- if (h5cvdata_name == NULL && check_vdname == -1) {
- printf("error,group name is not defined.\n");
- return FAIL;
- }
-
- if (h5cvdata_name == NULL && check_vdname == -2 ) {
- printf("cannot allocate memory for vdata.\n");
- return FAIL;
- }
-
- h5dset = H5Dcreate(group_id,h5cvdata_name,h5_ctype,h5d_sid,H5P_DEFAULT);
- if(h5dset <0) {
- printf("error in obtaining dataset.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- free(h5cvdata_name);
- return FAIL;
- }
- free(h5cvdata_name);
-
- if(H5Dwrite(h5dset,h5_cmemtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,vd_data)<0){
- printf("error in writing dataset converted from vdata.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- /* handle vdata attributes and vdata field attributes. */
-
- num_vd_attrs = VSfnattrs(vdata_id,_HDF_VDATA);
-
- if (num_vd_attrs == FAIL) {
- printf("error in obtaining attributes of vdata.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- /* when field_index = -1, only transfer vdata attribute.*/
-
- field_index = -1;
- if(vdata_transattrs(vdata_id,h5dset,num_vd_attrs,field_index,NULL)==FAIL){
- printf("error in translating vdata attibutes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- for (i =0;i< nfields;i++) {
-
- if(VFfieldname(vdata_id,i)== NULL) {
- printf("error in obtaining field name. \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- strcpy(fieldname,VFfieldname(vdata_id,i));
- num_vd_field_attrs = VSfnattrs(vdata_id,i);
- if(num_vd_field_attrs == FAIL){
- printf("error in number of vd field attribute \n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- if(vdata_transattrs(vdata_id,h5dset,num_vd_field_attrs,i,fieldname)
- ==FAIL){
- printf("error in transfering vdata attributes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
- }
- /* converting annotations of vdata into corresponding hdf5 attribute.*/
- if( Annoobj_h4_to_h5(file_id,vdata_ref,vdata_tag,h5dset)== FAIL){
- printf("fail to convert HDF4 VDATA annotation into hdf5 attributes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- /* converting predefined attributes. */
- strcpy(vdlabel,VDATALABEL);
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,vdlabel)==FAIL){
- printf("error in transfering vdata attributes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- if(vdata_name[0] != '\0') {
- if(h4_transpredattrs(h5dset,HDF4_OBJECT_NAME,vdata_name)==FAIL){
- printf("error in transfering vdata attributes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
- }
-
- if(h4_transnumattr(h5dset,HDF4_REF_NUM,vdata_ref)==FAIL){
- printf("error in transfering vdata attributes.\n");
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return FAIL;
- }
-
- H5Sclose(h5d_sid);
- H5Dclose(h5dset);
- VSdetach(vdata_id);
- free(h5memtype);
- free(h5type);
- free(h4memsize);
- free(h4size);
- free(vd_data);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: vdata_transattrs
- *
- * Purpose: translate Vdata attributes into attributes of the
- corresponding hdf5 dataset
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- vdata_id: vdata identifier
- h5dset: hdf5 dataset
- snum_vdattrs: number of vd attributes
- field_index: index of vdata fields
- attr_name: vdata(or vdata field) attribute name
- Out:
- Modifications:
-
- *-------------------------------------------------------------------------
- */
-
-int vdata_transattrs(int32 vdata_id,hid_t h5dset,int snum_vdattrs,
- int field_index,char* attr_name){
-
- char svdattr_name[2*MAX_NC_NAME];
- char* svdrepattr_name;
- char refstr[MAXREF_LENGTH];
-
- int32 count_svdadata;
- int32 svd_atype;
-
- size_t sh4_amemsize;
- size_t sh4_asize;
-
- hid_t sh5a_sid;
- hid_t sh5a_id;
- hid_t sh5_atype;
- hid_t sh5_amemtype;
- hid_t sh5str_type;
- hid_t sh5str_memtype;
-
- hsize_t sh5dims[1];
- void* svd_adata;
- herr_t sret;
- int i;
-
- /* zeroing out memory for svdattr_name and refstr */
- h4toh5_ZeroMemory(svdattr_name,2*MAX_NC_NAME);
- h4toh5_ZeroMemory(refstr,MAXREF_LENGTH);
-
- /* separate vdata attribute from vdata field attributes. */
-
- if (field_index < -1) {
- printf("error: check_field should be either -1(vdata) or ");
- printf(">=0(vdata field).\n");
- return FAIL;
- }
-
- for (i = 0;i < snum_vdattrs; i++) {
-
- /* if the field_index is 0, no field attribute exists, only
- VDATA attributes are converted.*/
-
- if (VSattrinfo(vdata_id,field_index,i,svdattr_name,&svd_atype,
- &count_svdadata,NULL)== FAIL){
- printf("unable to obtain attribute information. \n");
- return FAIL;
- }
-
- if(svdattr_name[0] == '\0') {
- svdrepattr_name = trans_obj_name(DFTAG_VG,i);
- strcpy(svdattr_name,svdrepattr_name);
- free(svdrepattr_name);
- }
-
- if (field_index == -1);
-
- else if (field_index != -1 && attr_name != NULL) {
-
- strcat(svdattr_name,":");
- strcat(svdattr_name,attr_name);
- }
-
- else {
-
- strcat(svdattr_name,":");
- strcat(svdattr_name,"HDF4_VDATA_ATTR_");
- if(conv_int_str(field_index,refstr)==FAIL) {
- printf("error in converting vdata field index to string.\n");
- return FAIL;
- }
- strcat(svdattr_name,refstr);
-
- }
-
- /* converting attribute data type into the corresponding hdf5 data type */
-
- if(h4type_to_h5type(svd_atype,&sh5_amemtype,&sh4_amemsize,
- &sh4_asize,&sh5_atype)==FAIL){
- printf("fail to translate vdata attribute datatype from H4 to H5.\n");
- return FAIL;
- }
-
- svd_adata = malloc(sh4_amemsize * count_svdadata);
-
- if(svd_adata == NULL) {
- printf("fail to allocate memory for vdata attribute data.\n");
- return FAIL;
- }
-
- if(VSgetattr(vdata_id,field_index,i,(VOIDP)svd_adata)==FAIL){
- printf("error in getting attributes of vdata. \n");
- free(svd_adata);
- return FAIL;
- }
-
- /* now do attribute-transferring:
- 1. deal with string data type
- 2. set attribute space
- 3. get attribute name */
-
- if (sh5_atype == H5T_STRING) {
-
- if ((sh5str_type = mkstr(count_svdadata,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making string for vdata attribute. \n");
- free(svd_adata);
- return FAIL;
- }
-
- if ((sh5str_memtype = mkstr(count_svdadata*sh4_amemsize,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making memory string for vdata attribute. \n");
- free(svd_adata);
- return FAIL;
- }
-
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space for ");
- printf("HDF4_OBJECT_TYPE VDATA. \n");
- free(svd_adata);
- return FAIL;
- }
-
-
- sh5a_id = H5Acreate(h5dset,svdattr_name,sh5str_type,
- sh5a_sid,H5P_DEFAULT);
-
- if (sh5a_id <0) {
- printf("failed to obtain attribute id for");
- printf(" HDF4_OBJECT_TYPE VDATA. \n");
- H5Sclose(sh5a_sid);
- free(svd_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)svd_adata);
-
- if (sret <0) {
- printf("fail to write vdata attr into hdf5 dataset attr\n ");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- free(svd_adata);
- return FAIL;
- }
-
- free(svd_adata);
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
-
- else {
-
- if(count_svdadata == 1) {
- sh5a_sid = H5Screate(H5S_SCALAR);
-
- if (sh5a_sid < 0) {
- printf("failed to create scalar space id for hdf5 attribute ");
- printf("of dataset converted from attribute of VDATA.\n");
- free(svd_adata);
- return FAIL;
- }
- }
- else {
- sh5dims[0] = count_svdadata;
- sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
-
- if (sh5a_sid < 0) {
- printf("failed to create simple space id for hdf5 attribute ");
- printf("of dataset converted from attribute of VDATA.\n");
- free(svd_adata);
- return FAIL;
- }
- }
-
- sh5a_id = H5Acreate(h5dset,svdattr_name,sh5_atype,
- sh5a_sid,H5P_DEFAULT);
-
- if(sh5a_id <0) {
- printf("failed to create attribute id for hdf5 attribute ");
- printf("of dataset converted from attribute of VDATA.\n");
- H5Sclose(sh5a_sid);
- free(svd_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)svd_adata);
-
- if(sret <0) {
- printf("failed to write attribute data for hdf5 attribute ");
- printf("of dataset converted from attribute of VDATA.\n");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- free(svd_adata);
- return FAIL;
- }
-
- sret = H5Aclose(sh5a_id);
- sret = H5Sclose(sh5a_sid);
- free(svd_adata);
- }
- }
- return SUCCEED;
-}
-/*-------------------------------------------------------------------------
- * Function: gen_h5comptype
- *
- * Purpose: generate hdf5 compound data type
-
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- vdata_id: vdata identifier
- nfields: number of fields
- sh4size: pointer to datatype size in memory
- sh4memsize: pointer to datatype size in memory
- sh5type: pointer to hdf5 datatype
- sh5memtype: pointer to actual hdf5 datatype in memory
- h5_ctype: hdf5 compound datatype
- h5_cmemtype: hdf5 compound datatype in memory
- Out:
- Modifications:
-
- *-------------------------------------------------------------------------
- */
-
-int gen_h5comptype(int32 vdata_id,int32 nfields,
- size_t* sh4size,size_t* sh4memsize,
- hid_t* sh5type,hid_t* sh5memtype,
- hid_t h5_ctype,hid_t h5_cmemtype) {
-
- char* fieldname;
- int32 fieldorder;
- size_t fil_offset;
- size_t mem_offset;
- hsize_t fielddim[1];
- hid_t h5str_type;
- int check_ifstr;/* flag to check if the h5 type is string.*/
- int i;
-
-
- check_ifstr = 0;
- fil_offset = 0;
- mem_offset = 0;
-
-
- for (i =0;i< nfields;i++) {
-
- fieldname = NULL;
- fieldorder = VFfieldorder(vdata_id,i);
-
- if(fieldorder == FAIL){
- printf("error in obtaining fieldorder.\n");
- return FAIL;
- }
-
- fieldname = VFfieldname(vdata_id,i);
- if(fieldname == NULL){
- printf("fail to obtain Vdata field name. \n");
- return FAIL;
- }
-
-
- /* when vdata is a character array, we will write the whole
- array as one hdf5 type string. */
-
- if(sh5type[i] == H5T_STRING) {
-
- if ((h5str_type = mkstr(sh4size[i]*fieldorder,H5T_STR_SPACEPAD))<0) {
- printf("error in making string of hdf5 string. \n");
- return FAIL;
- }
- sh5type[i] = h5str_type;
- check_ifstr = 1;
- }
-
- if (sh5memtype[i] == H5T_STRING) {
-
- if((h5str_type = mkstr(sh4memsize[i]*fieldorder,H5T_STR_SPACEPAD))<0){
- printf("error in making string for VDATA in memory. \n");
- return FAIL;
- }
- sh5memtype[i] = h5str_type;
-
- }
-
- fielddim[0] = fieldorder;
-
- /* if field type is an array, use H5Tinsert_array.
- When the data type is H5T_STRING,
- we will treat the the vdata as a HDF5 scalar type.*/
-
- if (fielddim[0] == 1 || check_ifstr == 1) {
-
- if(H5Tinsert(h5_ctype,fieldname,fil_offset,sh5type[i])<0) {
- printf("error inserting hdf5 compound datatype while ");
- printf("converting vdata.\n");
- return FAIL;
- }
-
- if(H5Tinsert(h5_cmemtype,fieldname,mem_offset,sh5memtype[i])<0){
- printf("error inserting hdf5 compound datatype of memory");
- printf(" while converting vdata.\n");
- return FAIL;
- }
- }
-
- else {
- hid_t arr_type; /* Array datatype for inserting fields */
-
- /* Create array datatype */
- if((arr_type=H5Tarray_create(sh5type[i],1,fielddim,NULL))<0) {
- printf("error creating array datatype.\n");
- return FAIL;
- }
-
- if(H5Tinsert(h5_ctype,fieldname,fil_offset,arr_type)<0) {
- printf("error inserting array into hdf5 compound datatype. \n");
- return FAIL;
- }
-
- /* Close array datatype */
- if(H5Tclose(arr_type)<0) {
- printf("error closing array datatype.\n");
- return FAIL;
- }
-
- /* Create array datatype */
- if((arr_type=H5Tarray_create(sh5memtype[i],1,fielddim,NULL))<0) {
- printf("error creating array datatype.\n");
- return FAIL;
- }
-
- if(H5Tinsert(h5_cmemtype,fieldname,mem_offset,arr_type)<0) {
- printf("error inserting array into hdf5 compound datatype for memory. \n");
- return FAIL;
- }
-
- /* Close array datatype */
- if(H5Tclose(arr_type)<0) {
- printf("error closing array datatype.\n");
- return FAIL;
- }
-
-
- }
-
- if( check_ifstr == 1) {
- fil_offset = fil_offset + sh4size[i]*fieldorder;
- mem_offset = mem_offset + sh4memsize[i]*fieldorder;
- check_ifstr = 0;
- }
- else {
-
- fil_offset = fil_offset + sh4size[i]*fieldorder;
- mem_offset = mem_offset + sh4memsize[i]*fieldorder;
- }
-
- }
-
- return SUCCEED;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/h4toh5vgroup.c b/tools/h4toh5vgroup.c
deleted file mode 100644
index 92a6735..0000000
--- a/tools/h4toh5vgroup.c
+++ /dev/null
@@ -1,812 +0,0 @@
-
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 2000 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-
-/******************************************************************************
-
- Description:
-
-1. converter
-
-See HDF4 to HDF5 mapping specification at
-(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
-from HDF4 object to HDF5 object.
-
-The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
-
-2. this file
-
-converting an hdf4 vgroup object into a hdf5 group.
-
-Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
-
-
-*****************************************************************************/
-
-
-#include "h4toh5main.h"
-
-
-/*-------------------------------------------------------------------------
- * Function: Vgroup_h4_to_h5
- *
- * Purpose: translate different Vgroup objects: vgroup,vdata,sds,image
- into hdf5 datasets and recursively call the routine
- *
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf4 file identifier
- vgroup_id: hdf4 vgroup id
- sd_id: sd interface id
- h5_group: hdf5 group id
- h5_dimgroup: hdf5 dimensional scale group id
- h5_palgroup: hdf5 palette group id
- Out:
-
- Modification:
- *-------------------------------------------------------------------------
- */
-
-
-int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid_t h5_dimgroup,hid_t h5_palgroup)
-
-{
-
- int32 vgroup_tag;
- int32 vgroup_ref;
- int32 obj_tag;
- int32 obj_ref;
- int32 num_gobjects;
- int i;
-
- char refstr[MAXREF_LENGTH];
- char vgroup_class[VGNAMELENMAX];
- char vgroup_name[VGNAMELENMAX];
-
- char* h5pgroup_name;
-
- int check_vgname;
- hid_t h5_pgroup;
-
- /*zeroing out memory for vgroup_class and vgroup_name */
- h4toh5_ZeroMemory(vgroup_class,VGNAMELENMAX);
- h4toh5_ZeroMemory(vgroup_name,VGNAMELENMAX);
-
- vgroup_tag = VQuerytag(vgroup_id);
- if(vgroup_tag == FAIL) {
- printf("error in obtaining vgroup tag.\n");
- return FAIL;
- }
-
- vgroup_ref = VQueryref(vgroup_id);
- if(vgroup_ref == FAIL) {
- printf("error in obtaining vgroup reference.\n");
- return FAIL;
- }
-
- if(Vgetname(vgroup_id,vgroup_name) == FAIL) {
- printf("error in obtaining vgroup name.\n");
- return FAIL;
- }
-
- if(Vgetclass(vgroup_id,vgroup_class) == FAIL) {
- printf("error in obtaining vgroup class name. \n");
- return FAIL;
- }
-
- /*** ignore reserved HDF group ***/
-
- if(vgroup_class != NULL) {
- if(strcmp(vgroup_class,_HDF_ATTRIBUTE)==0) return SUCCEED;
- if(strcmp(vgroup_class,_HDF_VARIABLE)==0) return SUCCEED;
- if(strcmp(vgroup_class,_HDF_DIMENSION)==0) return SUCCEED;
- if(strcmp(vgroup_class,_HDF_UDIMENSION)==0) return SUCCEED;
- if(strcmp(vgroup_class,_HDF_CDF)==0) return SUCCEED;
- if(strcmp(vgroup_class,GR_NAME)==0) return SUCCEED;
- if(strcmp(vgroup_class,RI_NAME)==0) return SUCCEED;
- }
-
- if(vgroup_name != NULL)
- if(strcmp(vgroup_name,GR_NAME)==0) return SUCCEED;
-
- h5pgroup_name = get_name(vgroup_ref,estnum_vg,vg_hashtab,&check_vgname);
-
- if(h5pgroup_name == NULL && check_vgname == 0 ) {
- printf("error,cannot find group\n");
- return FAIL;
- }
-
- if(h5pgroup_name == NULL && check_vgname ==-1 ) {
- printf("error,group name is not defined.\n");
- return FAIL;
- }
-
- /* create a hdf5 group under h5_group.*/
-
- h5_pgroup = H5Gcreate(h5_group,h5pgroup_name,0);
-
- if(h5_pgroup < 0) {
- printf("error in creating group. \n");
- free(h5pgroup_name);
- return FAIL;
- }
-
- /* vgroup attributes into corresponding hdf5 group attributes.*/
- if(vg_transattrs(vgroup_id,h5_pgroup)==FAIL) {
- printf("error in translating vgroup attributes into hdf5 group attr.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
-
- num_gobjects = Vntagrefs(vgroup_id);
-
- if(num_gobjects == FAIL) {
- printf("error in obtaining number of objects in the vgroup. \n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
-
- if(Annoobj_h4_to_h5(file_id,vgroup_ref,vgroup_tag,h5_pgroup)==FAIL) {
- printf("error in obtaining annotation of the vgroup.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
-
- for( i = 0;i<num_gobjects;i++) {
-
- if(Vgettagref(vgroup_id,i,&obj_tag,&obj_ref)==FAIL) {
- printf("failed to get object tag and ref of the current");
- printf(" object in this vgroup.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("failed to convert object reference number ");
- printf("into string format at vgroup_h4_to_h5 routine.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
-
- if (Visvg(vgroup_id,obj_ref)) {
-
- if(convert_vgroup(file_id,sd_id,obj_ref,h5pgroup_name,h5_pgroup,
- h5_dimgroup,h5_palgroup)== FAIL) {
- printf("convert_vgroup routine failed,");
- printf("cannot convert vgroup into hdf5 group successfully.\n");
- free(h5pgroup_name);
- H5Gclose(h5_pgroup);
- return FAIL;
- }
-
- }
- /* the object is independent vdata. */
- else if(Visvs(vgroup_id,obj_ref)) {
- if(convert_vdata(file_id,obj_ref,h5pgroup_name,h5_pgroup)==FAIL){
- printf("fail to convert vdata into hdf5 dataset.\n");
- free(h5pgroup_name);
- H5Gclose(h5_pgroup);
- return FAIL;
- }
- }
- else if(obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG) {
- if(convert_sds(file_id,sd_id,obj_ref,h5pgroup_name,h5_pgroup,
- h5_dimgroup)==FAIL){
- printf("fail to convert sds into hdf5 dataset.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
- }
- else if(obj_tag == DFTAG_RIG) {
- if(convert_image(file_id,obj_ref,h5pgroup_name,
- h5_pgroup,h5_palgroup)==FAIL){
- printf("fail to convert image into hdf5 dataset.\n");
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return FAIL;
- }
- }
- }
-
- H5Gclose(h5_pgroup);
- free(h5pgroup_name);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: convert_vgroup
- *
- * Purpose: subroutine interface for better modularity of vgroup_h4_to_h5
- * In this routine, 1) h5 vgroup name is obtained;
- 2) vgroup_h4_to_h5 is called again for
- unvisited vgroups
- 3) HardLink is created for visited vgroups
-
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf4 file identifier
- sd_id: sd interface id
- obj_ref: object reference number
- h5pgroup_name: h5 group name
- h5_pgroup: hdf5 group id
- h5_dimgroup: hdf5 dimensional scale group id
- h5_palgroup: hdf5 palette group id
-
- *-------------------------------------------------------------------------
- */
-
-int convert_vgroup(int32 file_id,int32 sd_id, int32 obj_ref,
- char* h5pgroup_name,hid_t h5_pgroup,hid_t h5_dimgroup,
- hid_t h5_palgroup) {
-
- int32 vgroup_cid;
- int32 istat;
- int check_vgname;
- char refstr[MAXREF_LENGTH];
- char cvgroup_name[VGNAMELENMAX];
- char* cor_cvgroupname;
- char* h5cgroup_name;
- char* h5lgroup_name;
- int check_vgroup;
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("converting integer into string format.\n");
- return FAIL;
- }
-
- vgroup_cid = Vattach(file_id,obj_ref,"r");
- if(vgroup_cid == FAIL) {
- printf("error in getting vgroup id.\n");
- return FAIL;
- }
-
- /* recursively obtain information from the group*/
- /* check whether it is looked up, if yes, create a hard link.*/
-
- istat = Vgetname(vgroup_cid,cvgroup_name);
- if(istat == FAIL) {
- printf("failed to get the name of vgroup.\n");
- Vdetach(vgroup_cid);
- return FAIL;
- }
-
- /* look up vg hashtable and see whether this object is touched.*/
- check_vgroup = lookup(obj_ref,estnum_vg,vg_hashtab);
-
- /* if this vgroup has not been touched, convert it into hdf5 group.
- else create a hard link to the existing group.*/
-
- cor_cvgroupname = correct_name(cvgroup_name);
- if(cor_cvgroupname == NULL) {
- printf("error in generating corrected vgroup name. \n");
- Vdetach(vgroup_cid);
- return FAIL;
- }
- if(check_vgroup == 0) {
-
- /* checking whether vgroup name contains ORI_SLASH, changing into CHA_SLASH.*/
-
- h5cgroup_name = get_obj_aboname(cor_cvgroupname,refstr,h5pgroup_name,
- HDF4_VGROUP);
- if(h5cgroup_name == NULL) {
- printf("error in getting the group name.\n");
- Vdetach(vgroup_cid);
- free(cor_cvgroupname);
- return FAIL;
- }
-
- free(cor_cvgroupname);
- if(set_name(obj_ref,estnum_vg,vg_hashtab,h5cgroup_name)== FAIL) {
- printf("error in setting group name.\n");
- Vdetach(vgroup_cid);
- free(h5cgroup_name);
- return FAIL;
- }
- if(Vgroup_h4_to_h5(file_id,vgroup_cid,sd_id,h5_pgroup,
- h5_dimgroup,h5_palgroup)== FAIL) {
- printf("error in transferring vgroup into hdf5 group.\n");
- Vdetach(vgroup_cid);
- free(h5cgroup_name);
- return FAIL;
- }
- free(h5cgroup_name);
-
- }
-
- else {
-
- h5cgroup_name = get_name(obj_ref,estnum_vg,vg_hashtab,&check_vgname);
- if(h5cgroup_name == NULL && check_vgname ==0 ) {
- printf("error,cannot find group\n");
- Vdetach(vgroup_cid);
- return FAIL;
- }
-
- if(h5cgroup_name == NULL && check_vgname == -1 ) {
- printf("error,group name is not defined.\n");
- Vdetach(vgroup_cid);
- return FAIL;
- }
-
- /* create HL */
-
-
- h5lgroup_name = get_obj_aboname(cor_cvgroupname,refstr,h5pgroup_name,
- HDF4_VGROUP);
- if(h5lgroup_name == NULL) {
- printf("failed to obtain group name.\n");
- Vdetach(vgroup_cid);
- free(h5cgroup_name);
- free(cor_cvgroupname);
- return FAIL;
- }
- free(cor_cvgroupname);
- if(H5Glink(h5_pgroup,H5G_LINK_HARD,h5cgroup_name,h5lgroup_name)<0) {
- printf("cannot make hard link for two groups.\n");
- Vdetach(vgroup_cid);
- free(h5cgroup_name);
- free(h5lgroup_name);
- return FAIL;
- }
- free(h5cgroup_name);
- free(h5lgroup_name);
- }
-
- Vdetach(vgroup_cid);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: convert_vdata
- *
- * Purpose: subroutine interface for better modularity of vgroup_h4_to_h5
- * In this routine, 1) h5 vdata name is obtained;
- 2) vdata_h4_to_h5 is called for unvisited
- vdatas
- 3) HardLink is created for visited vdatas
-
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf4 file identifier
- obj_ref: object reference number
- h5pgroup_name: h5 group name
- h5_pgroup: hdf5 group id
-
- *-------------------------------------------------------------------------
- */
-
-int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup) {
-
- int32 vdata_id;
- int check_vdata;
- int check_vdname;
- int32 istat;
- char refstr[MAXREF_LENGTH];
- char cvdata_name[VGNAMELENMAX];
- char* cor_cvdataname;
- char* h5cvdata_name;
- char* h5lvdata_name;
-
- vdata_id = VSattach(file_id,obj_ref,"r");
- if(vdata_id == FAIL) {
- printf("error in attaching vdata. \n");
- return FAIL;
- }
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("converting integer into string format.\n");
- VSdetach(vdata_id);
- return FAIL;
- }
-
- istat = VSisattr(vdata_id);
- if (istat == FAIL) {
- printf("error in checking vdata attribute. \n");
- VSdetach(vdata_id);
- return FAIL;
- }
-
- if(istat); /*ignore, dependent vdata(attributes, etc.)can be retrieved later.*/
-
- else { /* independent vdata, read in */
-
- check_vdata = lookup(obj_ref,estnum_vd,vd_hashtab);
-
- if(check_vdata < 0) {
- printf("failed to look up the object.\n");
- VSdetach(vdata_id);
- return FAIL;
- }
-
- if(VSQueryname(vdata_id,cvdata_name)==FAIL) {
- printf("error in querying name. \n");
- VSdetach(vdata_id);
- return FAIL;
- }
-
- cor_cvdataname = correct_name(cvdata_name);
- if(cor_cvdataname == NULL) {
- printf("error in generating corrected vdata name. \n");
- VSdetach(vdata_id);
- return FAIL;
- }
- if(check_vdata ==0) {
- h5cvdata_name = get_obj_aboname(cor_cvdataname,refstr,h5pgroup_name,
- HDF4_VDATA);
- if(h5cvdata_name == NULL) {
- printf("cannot obtain the converted hdf5 dataset name from vdata.\n");
- VSdetach(vdata_id);
- free(cor_cvdataname);
- return FAIL;
- }
- free(cor_cvdataname);
- if(set_name(obj_ref,estnum_vd,vd_hashtab,h5cvdata_name)== FAIL){
- printf("failed to obtain vdata name.\n");
- VSdetach(vdata_id);
- free(h5cvdata_name);
- return FAIL;
- }
-
- if(Vdata_h4_to_h5(file_id,vdata_id,h5_pgroup)==FAIL){
- printf("failed to transfer vdata into hdf5 dataset.\n");
- VSdetach(vdata_id);
- free(h5cvdata_name);
- return FAIL;
- }
- free(h5cvdata_name);
- }
-
- else {
-
- h5cvdata_name = get_name(obj_ref,estnum_vd,vd_hashtab,
- &check_vdname);
-
- if(h5cvdata_name == NULL && check_vdname ==0 ){
- printf("error,cannot find vdata\n");
- VSdetach(vdata_id);
- return FAIL;
- }
- if(h5cvdata_name == NULL && check_vdname ==-1 ){
- printf("error,vdata name is not defined.\n");
- VSdetach(vdata_id);
- return FAIL;
- }
- /*create HL,
- for the time being, we will use absolute path. */
-
- h5lvdata_name = get_obj_aboname(cor_cvdataname,refstr,h5pgroup_name,
- HDF4_VDATA);
- if(h5lvdata_name == NULL) {
- printf("error in obtaining vdata name.\n");
- VSdetach(vdata_id);
- free(h5cvdata_name);
- free(cor_cvdataname);
- return FAIL;
- }
- free(cor_cvdataname);
- if(H5Glink(h5_pgroup,H5G_LINK_HARD,h5cvdata_name,h5lvdata_name)){
- printf("error in creating hardlink for hdf5 dataset");
- printf(" converted from vdata.\n");
- VSdetach(vdata_id);
- free(h5cvdata_name);
- free(h5lvdata_name);
- return FAIL;
- }
- free(h5cvdata_name);
- free(h5lvdata_name);
- }
- VSdetach(vdata_id);
- }
-
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: convert_sds
- *
- * Purpose: subroutine interface for better modularity of vgroup_h4_to_h5
- * In this routine, 1) h5 sds name is obtained;
- 2) sds_h4_to_h5 is called for unvisited
- sds objects
- 3) HardLink is created for visited sds
-
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- sd_id: hdf4 sds identifier
- obj_ref: object reference number
- h5_dimgroup: h5 dimensional scale group id
- h5_pgroup: hdf5 group id
-
- *-------------------------------------------------------------------------
- */
-int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup,hid_t h5_dimgroup) {
-
- int32 sd_index;
- int32 sds_id;
- int32 sds_rank;
- int32 sds_dimsizes[DIM_HASHSIZE];
- int32 sds_dtype;
- int32 num_sdsattrs;
- char sds_name[MAX_NC_NAME];
- char* cor_sdsname;
- int check_sds;
- int check_sdsname;
- char refstr[MAXREF_LENGTH];
- char* h5csds_name;
- char* h5lsds_name;
-
- sd_index = SDreftoindex(sd_id,obj_ref);
- if(sd_index == FAIL){
- printf("error in obtaining reference number of sds.\n");
- return FAIL;
- }
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("error in converting reference number into string type.\n");
- return FAIL;
- }
-
- sds_id = SDselect(sd_id,sd_index);
-
- if(sds_id == FAIL){
- printf("error in obtaining sd id.\n");
- return FAIL;
- }
-
- if(SDgetinfo(sds_id,sds_name,&sds_rank,sds_dimsizes,
- &sds_dtype,&num_sdsattrs)==FAIL) {
- printf("error in obtaining SD info.\n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- /* check whether this sds is touched. */
- check_sds = lookup(obj_ref,2*num_sds,sds_hashtab);
-
- cor_sdsname = correct_name(sds_name);
- if(cor_sdsname == NULL) {
- printf("error in generating corrected sds name. \n");
- SDendaccess(sds_id);
- return FAIL;
- }
-
- if(check_sds == 0) {
-
- /* obtain the absolute name of sds object, deal with the name clashing by
- looking up things in the "name hashing table".*/
-
- h5csds_name = get_obj_aboname(cor_sdsname,refstr,h5pgroup_name,HDF4_SDS);
- if(h5csds_name == NULL) {
- printf("error in obtaining sds name.\n");
- SDendaccess(sds_id);
- free(cor_sdsname);
- return FAIL;
- }
- free(cor_sdsname);
-
- /* put the absolute path of sds into "hashing table".*/
- if(set_name(obj_ref,2*num_sds,sds_hashtab,h5csds_name)==FAIL) {
- printf("error in setting object name.\n");
- SDendaccess(sds_id);
- free(h5csds_name);
- return FAIL;
- }
- /* convert the sds object into hdf5 dataset.*/
- if(Sds_h4_to_h5(file_id,sds_id,h5_pgroup,h5_dimgroup)==FAIL){
- printf("error in translating sds into hdf5 dataset.\n");
- SDendaccess(sds_id);
- free(h5csds_name);
- return FAIL;
- }
- free(h5csds_name);
- }
- else {
- /* if the object has been touched, create a hard link instead.*/
- h5csds_name = get_name(obj_ref,2*num_sds,sds_hashtab,&check_sdsname);
- if(h5csds_name == NULL) {
- printf("error in getting sds name \n");
- SDendaccess(sds_id);
- return FAIL;
- }
- /*... ADD in the code. create HL,
- for the time being, we will use absolute path. */
- h5lsds_name = get_obj_aboname(cor_sdsname,refstr,h5pgroup_name,
- HDF4_SDS);
- if(h5lsds_name == NULL) {
- printf("error in getting sds link name.\n");
- SDendaccess(sds_id);
- free(h5csds_name);
- free(cor_sdsname);
- return FAIL;
- }
- free(cor_sdsname);
- if(H5Glink(h5_pgroup,H5G_LINK_HARD,h5csds_name,h5lsds_name) <0) {
- printf("error in getting hard link \n");
- SDendaccess(sds_id);
- free(h5csds_name);
- free(h5lsds_name);
- return FAIL;
- }
-
- free(h5csds_name);
- free(h5lsds_name);
- }
- SDendaccess(sds_id);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: convert_image
- *
- * Purpose: subroutine interface for better modularity of vgroup_h4_to_h5
- * In this routine, 1) h5 vdata name is obtained;
- 2) image_h4_to_h5 is called for unvisited
- images
- 3) Hard Link is created for visited images
-
- * Return: FAIL if failed, SUCCEED if successful.
- *
- * In :
- file_id: hdf4 file identifier
- obj_ref: object reference number
- h5pgroup_name: h5 group name
- h5_pgroup: hdf5 group id
- h5_palgroup: hdf5 palette group id
-
- *-------------------------------------------------------------------------
- */
-int convert_image(int32 file_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup,hid_t h5_palgroup) {
-
- int32 gr_id;
- int32 gr_index;
- int32 ri_id;
- int32 istat;
- char* h5cimage_name;
- char* h5limage_name;
- char refstr[MAXREF_LENGTH];
- char image_name[MAX_GR_NAME];
- char* cor_imagename;
-
- int check_imagename;
- int check_image;
-
-
- gr_id = GRstart(file_id);
- if(gr_id == FAIL) {
- printf("error in obtaining gr id. \n");
- return FAIL;
- }
-
- if(conv_int_str(obj_ref,refstr)== FAIL) {
- printf("converting integer into string format.\n");
- return FAIL;
- }
-
- gr_index= GRreftoindex(gr_id,obj_ref);
- if(gr_index == FAIL) {
- printf("error in getting gr index.\n");
- return FAIL;
- }
-
- ri_id = GRselect(gr_id,gr_index);
- if(ri_id == FAIL) {
- printf("error in selecting gr interface.\n");
- return FAIL;
- }
-
- istat = GRgetiminfo(ri_id, image_name, NULL, NULL, NULL, NULL, NULL);
-
- if(istat == FAIL) {
- GRendaccess(ri_id);
- printf("error in getting GR images.\n");
- return FAIL;
- }
-
- /* checking whether image name contains ORI_SLASH,
- changing into CHA_SLASH.*/
-
- cor_imagename = correct_name(image_name);
- if(cor_imagename == NULL) {
- printf("error in generating corrected image name. \n");
- GRendaccess(ri_id);
- return FAIL;
- }
-
- /* check whether this image is touched. */
- check_image = lookup(obj_ref,2*num_images,gr_hashtab);
-
- if(check_image == 0) {
-
- /* obtain the absolute name of image object, deal with the name clashing by
- looking up things in the "name hashing table".*/
-
- h5cimage_name = get_obj_aboname(cor_imagename,refstr,h5pgroup_name,
- HDF4_IMAGE);
- if(h5cimage_name == NULL) {
- printf("error in getting image name.\n");
- GRendaccess(ri_id);
- free(cor_imagename);
- return FAIL;
- }
- free(cor_imagename);
-
- if(set_name(obj_ref,2*num_images,gr_hashtab,h5cimage_name)==FAIL) {
- printf("error setting image name.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- return FAIL;
- }
- if(Image_h4_to_h5(file_id,ri_id,h5_pgroup,h5_palgroup)==FAIL) {
- printf("error in transferring image name into hdf5 dataset.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- return FAIL;
- }
- free(h5cimage_name);
- }
-
- else{
-
- /*if the object is visited, create HL. */
-
- h5cimage_name = get_name(obj_ref,2*num_images,gr_hashtab,
- &check_imagename);
-
- if(h5cimage_name == NULL) {
- printf("error in getting image name into hdf5 dataset.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- return FAIL;
- }
- h5limage_name = get_obj_aboname(cor_imagename,refstr,h5pgroup_name,
- HDF4_IMAGE);
-
- if(h5limage_name == NULL) {
- printf("error in getting link image name into hdf5 dataset.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- free(cor_imagename);
- return FAIL;
- }
- free(cor_imagename);
-
- if(H5Glink(h5_pgroup,H5G_LINK_HARD,h5cimage_name,h5limage_name)<0){
- printf("error in linking two groups.\n");
- GRendaccess(ri_id);
- free(h5cimage_name);
- free(h5limage_name);
- return FAIL;
- }
- free(h5cimage_name);
- free(h5limage_name);
- }
-
- GRendaccess(ri_id);
- /* this is for efficient reason, we will comment out GRend.
- GRend(gr_id);*/
-
- return SUCCEED;
-}
-
-
-
-
-
diff --git a/tools/h5debug.c b/tools/h5debug.c
deleted file mode 100644
index 76eb472..0000000
--- a/tools/h5debug.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*-------------------------------------------------------------------------
- * Copyright (C) 1997 National Center for Supercomputing Applications.
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- *
- * Created: debug.c
- * Jul 18 1997
- * Robb Matzke <matzke@llnl.gov>
- *
- * Purpose: Debugs an existing HDF5 file at a low level.
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-#define H5F_PACKAGE /*suppress error about including H5Fpkg */
-
-#include <H5private.h>
-#include <H5Iprivate.h>
-#include <H5Bprivate.h>
-#include <H5Pprivate.h>
-#include <H5Fpkg.h>
-#include <H5Gprivate.h>
-#include <H5HGprivate.h>
-#include <H5HLprivate.h>
-#include <H5Oprivate.h>
-
-/* File drivers */
-#include <H5FDfamily.h>
-
-#define INDENT 3
-#define VCOL 50
-
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Usage: debug FILENAME [OFFSET]
- *
- * Return: Success: exit (0)
- *
- * Failure: exit (non-zero)
- *
- * Programmer: Robb Matzke
- * matzke@llnl.gov
- * Jul 18 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-main(int argc, char *argv[])
-{
- hid_t fid, plist=H5P_DEFAULT;
- H5F_t *f;
- haddr_t addr=0, extra=0;
- uint8_t sig[16];
- intn i, ndims;
- herr_t status = SUCCEED;
-
- if (argc == 1) {
- fprintf(stderr,
- "Usage: %s filename [signature addr [extra]]\n", argv[0]);
- HDexit(1);
- }
-
- /*
- * Open the file and get the file descriptor.
- */
- if (strchr (argv[1], '%')) {
- plist = H5Pcreate (H5P_FILE_ACCESS);
- H5Pset_fapl_family (plist, (hsize_t)0, H5P_DEFAULT);
- }
- if ((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, plist)) < 0) {
- fprintf(stderr, "cannot open file\n");
- HDexit(1);
- }
- if (NULL == (f = H5I_object(fid))) {
- fprintf(stderr, "cannot obtain H5F_t pointer\n");
- HDexit(2);
- }
-
- /*
- * Parse command arguments.
- */
- if (argc > 2) {
- printf("New address: %s\n", argv[2]);
- addr = HDstrtoll(argv[2], NULL, 0);
- }
- if (argc > 3) {
- extra = HDstrtoll(argv[3], NULL, 0);
- }
- /*
- * Read the signature at the specified file position.
- */
- HDfprintf(stdout, "Reading signature at address %a (rel)\n", addr);
- if (H5F_block_read(f, H5FD_MEM_SUPER, addr, (hsize_t)sizeof(sig), H5P_DEFAULT, sig)<0) {
- fprintf(stderr, "cannot read signature\n");
- HDexit(3);
- }
- if (!HDmemcmp(sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) {
- /*
- * Debug the boot block.
- */
- status = H5F_debug(f, addr, stdout, 0, VCOL);
-
- } else if (!HDmemcmp(sig, H5HL_MAGIC, H5HL_SIZEOF_MAGIC)) {
- /*
- * Debug a local heap.
- */
- status = H5HL_debug(f, addr, stdout, 0, VCOL);
-
- } else if (!HDmemcmp (sig, H5HG_MAGIC, H5HG_SIZEOF_MAGIC)) {
- /*
- * Debug a global heap collection.
- */
- status = H5HG_debug (f, addr, stdout, 0, VCOL);
-
- } else if (!HDmemcmp(sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) {
- /*
- * Debug a symbol table node.
- */
- status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra);
-
- } else if (!HDmemcmp(sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) {
- /*
- * Debug a B-tree. B-trees are debugged through the B-tree
- * subclass. The subclass identifier is the byte immediately
- * after the B-tree signature.
- */
- H5B_subid_t subtype = (H5B_subid_t)sig[H5B_SIZEOF_MAGIC];
-
- switch (subtype) {
- case H5B_SNODE_ID:
- status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra);
- break;
-
- case H5B_ISTORE_ID:
- ndims = (int)extra;
- status = H5F_istore_debug (f, addr, stdout, 0, VCOL, ndims);
- break;
-
- default:
- fprintf(stderr, "Unknown B-tree subtype %u\n",
- (unsigned)(subtype));
- HDexit(4);
- }
-
- } else if (sig[0] == H5O_VERSION) {
- /*
- * This could be an object header. Since they don't have a signature
- * it's a somewhat "ify" detection.
- */
- status = H5O_debug(f, addr, stdout, 0, VCOL);
-
- } else {
- /*
- * Got some other unrecognized signature.
- */
- printf("%-*s ", VCOL, "Signature:");
- for (i = 0; i < 8; i++) {
- if (sig[i] > ' ' && sig[i] <= '~' && '\\' != sig[i]) {
- HDputchar(sig[i]);
- } else if ('\\' == sig[i]) {
- HDputchar('\\');
- HDputchar('\\');
- } else {
- printf("\\%03o", sig[i]);
- }
- }
- HDputchar('\n');
-
- fprintf(stderr, "unknown signature\n");
- HDexit(4);
- }
-
- if (status < 0) {
- fprintf(stderr, "An error occurred\n");
- HDexit(5);
- }
- H5Fclose(fid);
- return 0;
-}
diff --git a/tools/h5dump.c b/tools/h5dump.c
deleted file mode 100644
index dab11d7..0000000
--- a/tools/h5dump.c
+++ /dev/null
@@ -1,4550 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * Copyright (C) 1998 - 2001
- * National Center for Supercomputing Applications
- * All rights reserved.
- *
- *-------------------------------------------------------------------------
- */
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "h5dump.h"
-#include "H5private.h"
-#include "h5tools.h"
-
-/* module-scoped variables */
-static int display_oid = 0;
-static int display_data = 1;
-static int d_status = EXIT_SUCCESS;
-static int unamedtype = 0; /* shared data type with no name */
-static int prefix_len = 1024;
-static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;
-static char *prefix;
-
-static const dump_header *dump_header_format;
-
-/**
- ** Added for XML **
- **/
-
-/* fill_ref_path_table is called to inialize the object reference paths. */
-static herr_t fill_ref_path_table(hid_t, const char *, void UNUSED *);
-
-/* module-scoped variables for XML option */
-#define DEFAULT_DTD "http://hdf.ncsa.uiuc.edu/DTDs/HDF5-File.dtd"
-
-static int doxml = 0;
-static const char *xml_dtd_uri = NULL;
-static hid_t thefile = -1;
-/** end XML **/
-
-/* internal functions */
-static void dump_oid(hid_t oid);
-static void print_enum(hid_t type);
-static herr_t dump_all(hid_t group, const char *name, void *op_data);
-static char *lookup_ref_path(hobj_ref_t *);
-static void check_compression(hid_t);
-static struct ref_path_table_entry_t *ref_path_table_lookup(const char *);
-
-/* external functions */
-extern int print_data(hid_t, hid_t, int);
-
-static h5dump_t dataformat = {
- 0, /*raw */
-
- "", /*fmt_raw */
- "%d", /*fmt_int */
- "%u", /*fmt_uint */
- "%d", /*fmt_schar */
- "%u", /*fmt_uchar */
- "%d", /*fmt_short */
- "%u", /*fmt_ushort */
- "%ld", /*fmt_long */
- "%lu", /*fmt_ulong */
- NULL, /*fmt_llong */
- NULL, /*fmt_ullong */
- "%g", /*fmt_double */
- "%g", /*fmt_float */
-
- 0, /*ascii */
- 0, /*str_locale */
- 0, /*str_repeat */
-
- "[ ", /*arr_pre */
- ", ", /*arr_sep */
- " ]", /*arr_suf */
- 1, /*arr_linebreak */
-
- "", /*cmpd_name */
- ",\n", /*cmpd_sep */
- "{\n", /*cmpd_pre */
- "}", /*cmpd_suf */
- "\n", /*cmpd_end */
-
- ",", /*vlen_sep */
- "(", /*vlen_pre */
- ")", /*vlen_suf */
- "", /*vlen_end */
-
- "%s", /*elmt_fmt */
- ",", /*elmt_suf1 */
- " ", /*elmt_suf2 */
-
- "", /*idx_n_fmt */
- "", /*idx_sep */
- "", /*idx_fmt */
-
- 80, /*line_ncols *//*standard default columns */
- 0, /*line_per_line */
- "", /*line_pre */
- "%s", /*line_1st */
- "%s", /*line_cont */
- "", /*line_suf */
- "", /*line_sep */
- 1, /*line_multi_new */
- " ", /*line_indent */
-
- 1, /*skip_first */
-
- 1, /*obj_hidefileno */
- " %lu:%lu", /*obj_format */
-
- 1, /*dset_hidefileno */
- "DATASET %lu:%lu ", /*dset_format */
- "%s", /*dset_blockformat_pre */
- "%s", /*dset_ptformat_pre */
- "%s", /*dset_ptformat */
-};
-
-/**
- ** Added for XML **
- **/
-/*
- * Alternative formating for data dumped to XML
- * In general, the numbers are the same, but separators
- * except spaces are not used.
- *
- * Some of these are not used, as some kinds of data are
- * dumped in completely new subroutines.
- *
- * Some of this formatting may yet need to change.
- *
- * This table only affects XML output.
- */
-static h5dump_t xml_dataformat = {
- 0, /*raw */
-
- "", /*fmt_raw */
- "%d", /*fmt_int */
- "%u", /*fmt_uint */
- "%d", /*fmt_schar */
- "%u", /*fmt_uchar */
- "%d", /*fmt_short */
- "%u", /*fmt_ushort */
- "%ld", /*fmt_long */
- "%lu", /*fmt_ulong */
- NULL, /*fmt_llong */
- NULL, /*fmt_ullong */
- "%g", /*fmt_double */
- "%g", /*fmt_float */
-
- 0, /*ascii */
- 0, /*str_locale */
- 0, /*str_repeat */
-
- " ", /*arr_pre */
- " ", /*arr_sep */
- " ", /*arr_suf */
- 1, /*arr_linebreak */
-
- "", /*cmpd_name */
- " ", /*cmpd_sep */
- "", /*cmpd_pre */
- "", /*cmpd_suf */
- "", /*cmpd_end */
-
- " ", /*vlen_sep */
- " ", /*vlen_pre */
- " ", /*vlen_suf */
- "", /*vlen_end */
-
- "%s", /*elmt_fmt */
- " ", /*elmt_suf1 */
- "", /*elmt_suf2 */
-
- "", /*idx_n_fmt */
- "", /*idx_sep */
- "", /*idx_fmt */
-
- 80, /*line_ncols *//*standard default columns */
- 0, /*line_per_line */
- "", /*line_pre */
- "%s", /*line_1st */
- "%s", /*line_cont */
- "", /*line_suf */
- "", /*line_sep */
- 1, /*line_multi_new */
- " ", /*line_indent */
-
- 1, /*skip_first */
-
- 1, /*obj_hidefileno */
- " %lu:%lu", /*obj_format */
-
- 1, /*dset_hidefileno */
- "DATASET %lu:%lu ", /*dset_format */
- "%s", /*dset_blockformat_pre */
- "%s", /*dset_ptformat_pre */
- "%s", /*dset_ptformat */
-};
-
-/** XML **/
-
-static const dump_header standardformat = {
- "standardformat", /*name */
- "HDF5", /*fileebgin */
- "", /*fileend */
- BOOT_BLOCK, /*bootblockbegin */
- "", /*bootblockend */
- GROUPNAME, /*groupbegin */
- "", /*groupend */
- DATASET, /*datasetbegin */
- "", /*datasetend */
- ATTRIBUTE, /*attributebegin */
- "", /*attributeend */
- DATATYPE, /*datatypebegin */
- "", /*datatypeend */
- DATASPACE, /*dataspacebegin */
- "", /*dataspaceend */
- DATA, /*databegin */
- "", /*dataend */
- SOFTLINK, /*softlinkbegin */
- "", /*softlinkend */
-
- "{", /*fileblockbegin */
- "}", /*fileblockend */
- "{", /*bootblockblockbegin */
- "}", /*bootblockblockend */
- "{", /*groupblockbegin */
- "}", /*groupblockend */
- "{", /*datasetblockbegin */
- "}", /*datasetblockend */
- "{", /*attributeblockbegin */
- "}", /*attributeblockend */
- "", /*datatypeblockbegin */
- "", /*datatypeblockend */
- "", /*dataspaceblockbegin */
- "", /*dataspaceblockend */
- "{", /*datablockbegin */
- "}", /*datablockend */
- "{", /*softlinkblockbegin */
- "}", /*softlinkblockend */
- "{", /*strblockbegin */
- "}", /*strblockend */
- "{", /*enumblockbegin */
- "}", /*enumblockend */
- "{", /*structblockbegin */
- "}", /*structblockend */
- "{", /*vlenblockbegin */
- "}", /*vlenblockend */
-
- "", /*dataspacedescriptionbegin */
- "", /*dataspacedescriptionend */
- "(", /*dataspacedimbegin */
- ")", /*dataspacedimend */
-};
-
-/**
- ** Added for XML **
- **/
-/* The 'header' formats for XML -- mostly null
- *
- * XML output has values embedded in the 'headers', so
- * all the XML headers are done on a case by case basis.
- */
-static const dump_header xmlformat = {
- "xml", /*name */
- "", /*filebegin */
- "</HDF5-File>", /*fileend */
- "", /*bootblockbegin */
- "", /*bootblockend */
- "", /*groupbegin */
- "</Group>", /*groupend */
- "", /*datasetbegin */
- "</Dataset>", /*datasetend */
- "", /*attributebegin */
- "</Attribute>", /*attributeend */
- "<DataType>", /*datatypeend */
- "</DataType>", /*datatypeend */
- "<Dataspace>", /*dataspacebegin */
- "</Dataspace>", /*dataspaceend */
- "<Data>", /*databegin */
- "</Data>", /*dataend */
- "", /*softlinkbegin */
- "", /*softlinkend */
-
- "", /*fileblockbegin */
- "", /*fileblockend */
- "", /*bootblockblockbegin */
- "", /*bootblockblockend */
- "", /*groupblockbegin */
- "", /*groupblockend */
- "", /*datasetblockbegin */
- "", /*datasetblockend */
- "", /*attributeblockbegin */
- "", /*attributeblockend */
- "", /*datatypeblockbegin */
- "", /*datatypeblockend */
- "", /*dataspaceblockbegin */
- "", /*dataspaceblockend */
- "", /*datablockbegin */
- "", /*datablockend */
- "", /*softlinkblockbegin */
- "", /*softlinkblockend */
- "", /*strblockbegin */
- "", /*strblockend */
- "", /*enumblockbegin */
- "", /*enumblockend */
- "", /*structblockbegin */
- "", /*structblockend */
- "", /*vlenblockbegin */
- "", /*vlenblockend */
-
- "", /*dataspacedescriptionbegin */
- "", /*dataspacedescriptionend */
- "", /*dataspacedimbegin */
- "", /*dataspacedimend */
-};
-
-/** XML **/
-
-/**
- ** Added for XML **
- **/
-/* internal functions used by XML option */
-static void xml_print_datatype(hid_t);
-static void xml_print_enum(hid_t);
-static int xml_print_refs(hid_t, int);
-static int xml_print_strs(hid_t, int);
-static hobj_ref_t *ref_path_table_put(hid_t, const char *);
-static char *xml_escape_the_string(const char *, int);
-static char *xml_escape_the_name(const char *);
-
-/**
- ** Change for XML **
- **
- ** The 'dump_xxx' functions have two versions, standard and XML.
- **
- ** They are called indirectly through the 'dump_function_table'.
- ** e.g., dump_group(...) becomes dump_functions->dump_group(...);
- **
- ** The standard functions are unchanged except for the way
- ** they are called
- **/
-
-/* The dump functions of the dump_function_table */
-
-/* standard format: no change */
-static void dump_group(hid_t, const char *);
-static void dump_dataset(hid_t, const char *);
-static void dump_data(hid_t, int);
-static void dump_named_datatype(hid_t, const char *);
-static void dump_dataspace(hid_t space);
-static void dump_datatype(hid_t type);
-static herr_t dump_attr(hid_t attr, const char *attr_name,
- void UNUSED * op_data);
-
-/* XML format: same interface, alternaive output */
-
-static void xml_dump_group(hid_t, const char *);
-static void xml_dump_dataset(hid_t ds, const char *dsname);
-static void xml_dump_data(hid_t, int);
-static void xml_dump_named_datatype(hid_t, const char *);
-static void xml_dump_dataspace(hid_t space);
-static void xml_dump_datatype(hid_t type);
-static herr_t xml_dump_attr(hid_t attr, const char *attr_name,
- void UNUSED * op_data);
-
-/**
- ** Added for XML **
- **
- ** This is the global dispatch table for the dump functions.
- **/
-/* the table of dump functions */
-typedef struct dump_functions_t {
- void (*dump_group_function) (hid_t, const char *);
- void (*dump_named_datatype_function) (hid_t, const char *);
- void (*dump_dataset_function) (hid_t, const char *);
- void (*dump_dataspace_function) (hid_t);
- void (*dump_datatype_function) (hid_t);
- herr_t (*dump_attribute_function) (hid_t, const char *, void *);
- void (*dump_data_function) (hid_t, int);
-} dump_functions;
-
-/* Standard DDL output */
-static const dump_functions ddl_function_table = {
- dump_group,
- dump_named_datatype,
- dump_dataset,
- dump_dataspace,
- dump_datatype,
- dump_attr,
- dump_data
-};
-
-/* XML output */
-static const dump_functions xml_function_table = {
- xml_dump_group,
- xml_dump_named_datatype,
- xml_dump_dataset,
- xml_dump_dataspace,
- xml_dump_datatype,
- xml_dump_attr,
- xml_dump_data
-};
-
-/*
- * The global table is set to either ddl_function_table or
- * xml_function_table in the initialization.
- */
-static const dump_functions *dump_function_table;
-
-/* a structure to hold the subsetting particulars for a dataset */
-struct subset_t {
- hsize_t *start;
- hsize_t *stride;
- hsize_t *count;
- hsize_t *block;
-};
-
-/* a structure for handling the order command-line parameters come in */
-struct handler_t {
- void (*func)(hid_t, char *);
- char *obj;
- struct subset_t *subset_info;
-};
-
-/*
- * Command-line options: The user can specify short or long-named
- * parameters. The long-named ones can be partially spelled. When
- * adding more, make sure that they don't clash with each other.
- */
-static const char *s_opts = "hBHvVa:d:g:l:t:w:xD:o:s:T:c:k:";
-static struct long_options l_opts[] = {
- { "help", no_arg, 'h' },
- { "hel", no_arg, 'h' },
- { "boot-block", no_arg, 'B' },
- { "boot-bloc", no_arg, 'B' },
- { "boot-blo", no_arg, 'B' },
- { "boot-bl", no_arg, 'B' },
- { "boot-b", no_arg, 'B' },
- { "boot", no_arg, 'B' },
- { "boo", no_arg, 'B' },
- { "bo", no_arg, 'B' },
- { "header", no_arg, 'H' },
- { "heade", no_arg, 'H' },
- { "head", no_arg, 'H' },
- { "hea", no_arg, 'H' },
- { "object-ids", no_arg, 'i' },
- { "object-id", no_arg, 'i' },
- { "object-i", no_arg, 'i' },
- { "object", no_arg, 'i' },
- { "objec", no_arg, 'i' },
- { "obje", no_arg, 'i' },
- { "obj", no_arg, 'i' },
- { "ob", no_arg, 'i' },
- { "version", no_arg, 'V' },
- { "versio", no_arg, 'V' },
- { "versi", no_arg, 'V' },
- { "vers", no_arg, 'V' },
- { "ver", no_arg, 'V' },
- { "ve", no_arg, 'V' },
- { "attribute", require_arg, 'a' },
- { "attribut", require_arg, 'a' },
- { "attribu", require_arg, 'a' },
- { "attrib", require_arg, 'a' },
- { "attri", require_arg, 'a' },
- { "attr", require_arg, 'a' },
- { "att", require_arg, 'a' },
- { "at", require_arg, 'a' },
- { "block", require_arg, 'k' },
- { "bloc", require_arg, 'k' },
- { "blo", require_arg, 'k' },
- { "bl", require_arg, 'k' },
- { "count", require_arg, 'c' },
- { "coun", require_arg, 'c' },
- { "cou", require_arg, 'c' },
- { "co", require_arg, 'c' },
- { "dataset", require_arg, 'd' },
- { "datase", require_arg, 'd' },
- { "datas", require_arg, 'd' },
- { "datatype", require_arg, 't' },
- { "datatyp", require_arg, 't' },
- { "dataty", require_arg, 't' },
- { "datat", require_arg, 't' },
- { "group", require_arg, 'g' },
- { "grou", require_arg, 'g' },
- { "gro", require_arg, 'g' },
- { "gr", require_arg, 'g' },
- { "output", require_arg, 'o' },
- { "outpu", require_arg, 'o' },
- { "outp", require_arg, 'o' },
- { "out", require_arg, 'o' },
- { "ou", require_arg, 'o' },
- { "soft-link", require_arg, 'l' },
- { "soft-lin", require_arg, 'l' },
- { "soft-li", require_arg, 'l' },
- { "soft-l", require_arg, 'l' },
- { "soft", require_arg, 'l' },
- { "sof", require_arg, 'l' },
- { "so", require_arg, 'l' },
- { "start", require_arg, 's' },
- { "star", require_arg, 's' },
- { "sta", require_arg, 's' },
- { "stride", require_arg, 'T' },
- { "strid", require_arg, 'T' },
- { "stri", require_arg, 'T' },
- { "str", require_arg, 'T' },
- { "width", require_arg, 'w' },
- { "widt", require_arg, 'w' },
- { "wid", require_arg, 'w' },
- { "wi", require_arg, 'w' },
- { "xml", no_arg, 'x' },
- { "xm", no_arg, 'x' },
- { "xml-dtd", require_arg, 'D' },
- { "xml-dt", require_arg, 'D' },
- { "xml-d", require_arg, 'D' },
- { NULL, 0, '\0' }
-};
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: Print the usage message about dumper
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-usage(const char *progname)
-{
- fflush(stdout);
- fprintf(stderr, "\
-usage: %s [OPTIONS] file\n\
- OPTIONS\n\
- -h, --help Print a usage message and exit\n\
- -B, --bootblock Print the content of the boot block\n\
- -H, --header Print the header only; no data is displayed\n\
- -i, --object-ids Print the object ids\n\
- -V, --version Print version number and exit\n\
- -a P, --attribute=P Print the specified attribute\n\
- -d P, --dataset=P Print the specified dataset\n\
- -g P, --group=P Print the specified group and all members\n\
- -l P, --soft-link=P Print the value(s) of the specified soft link\n\
- -o F, --output=F Output raw data into file F\n\
- -t T, --datatype=T Print the specified named data type\n\
- -w #, --width=# Set the number of columns of output\n\
- -x, --xml Output in XML\n\
- -D U, --xml-dtd=U Use the DTD at U\n\
-\n\
- P - is the full path from the root group to the object.\n\
- T - is the name of the data type.\n\
- F - is a filename.\n\
- # - is an integer greater than 1.\n\
- U - is a URI reference (as defined in [IETF RFC 2396],\n\
- updated by [IETF RFC 2732])\n\
-\n\
- Example:\n\
-\n\
- Attribute foo of the group /bar_none in file quux.h5\n\
-\n\
- h5dump -a /bar_none/foo quux.h5\n\
-\n", progname);
-}
-
-/*-------------------------------------------------------------------------
- * Function: print_datatype
- *
- * Purpose: print the data type.
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-print_datatype(hid_t type)
-{
- char *fname;
- hid_t nmembers, mtype, str_type;
- int i, j, ndims, perm[H5DUMP_MAX_RANK];
- size_t size;
- hsize_t dims[H5DUMP_MAX_RANK];
- H5T_str_t str_pad;
- H5T_cset_t cset;
- H5G_stat_t statbuf;
- hid_t super;
-
- switch (H5Tget_class(type)) {
- case H5T_INTEGER:
- if (H5Tequal(type, H5T_STD_I8BE)) {
- printf("H5T_STD_I8BE");
- } else if (H5Tequal(type, H5T_STD_I8LE)) {
- printf("H5T_STD_I8LE");
- } else if (H5Tequal(type, H5T_STD_I16BE)) {
- printf("H5T_STD_I16BE");
- } else if (H5Tequal(type, H5T_STD_I16LE)) {
- printf("H5T_STD_I16LE");
- } else if (H5Tequal(type, H5T_STD_I32BE)) {
- printf("H5T_STD_I32BE");
- } else if (H5Tequal(type, H5T_STD_I32LE)) {
- printf("H5T_STD_I32LE");
- } else if (H5Tequal(type, H5T_STD_I64BE)) {
- printf("H5T_STD_I64BE");
- } else if (H5Tequal(type, H5T_STD_I64LE)) {
- printf("H5T_STD_I64LE");
- } else if (H5Tequal(type, H5T_STD_U8BE)) {
- printf("H5T_STD_U8BE");
- } else if (H5Tequal(type, H5T_STD_U8LE)) {
- printf("H5T_STD_U8LE");
- } else if (H5Tequal(type, H5T_STD_U16BE)) {
- printf("H5T_STD_U16BE");
- } else if (H5Tequal(type, H5T_STD_U16LE)) {
- printf("H5T_STD_U16LE");
- } else if (H5Tequal(type, H5T_STD_U32BE)) {
- printf("H5T_STD_U32BE");
- } else if (H5Tequal(type, H5T_STD_U32LE)) {
- printf("H5T_STD_U32LE");
- } else if (H5Tequal(type, H5T_STD_U64BE)) {
- printf("H5T_STD_U64BE");
- } else if (H5Tequal(type, H5T_STD_U64LE)) {
- printf("H5T_STD_U64LE");
- } else if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
- printf("H5T_NATIVE_SCHAR");
- } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
- printf("H5T_NATIVE_UCHAR");
- } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
- printf("H5T_NATIVE_SHORT");
- } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
- printf("H5T_NATIVE_USHORT");
- } else if (H5Tequal(type, H5T_NATIVE_INT)) {
- printf("H5T_NATIVE_INT");
- } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
- printf("H5T_NATIVE_UINT");
- } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
- printf("H5T_NATIVE_LONG");
- } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
- printf("H5T_NATIVE_ULONG");
- } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
- printf("H5T_NATIVE_LLONG");
- } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
- printf("H5T_NATIVE_ULLONG");
- } else {
- printf("undefined integer");
- d_status = EXIT_FAILURE;
- }
- break;
-
- case H5T_FLOAT:
- if (H5Tequal(type, H5T_IEEE_F32BE)) {
- printf("H5T_IEEE_F32BE");
- } else if (H5Tequal(type, H5T_IEEE_F32LE)) {
- printf("H5T_IEEE_F32LE");
- } else if (H5Tequal(type, H5T_IEEE_F64BE)) {
- printf("H5T_IEEE_F64BE");
- } else if (H5Tequal(type, H5T_IEEE_F64LE)) {
- printf("H5T_IEEE_F64LE");
- } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
- printf("H5T_NATIVE_FLOAT");
- } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
- printf("H5T_NATIVE_DOUBLE");
- } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) {
- printf("H5T_NATIVE_LDOUBLE");
- } else {
- printf("undefined float");
- d_status = EXIT_FAILURE;
- }
- break;
-
- case H5T_TIME:
- printf("H5T_TIME: not yet implemented");
- break;
-
- case H5T_STRING:
- size = H5Tget_size(type);
- str_pad = H5Tget_strpad(type);
- cset = H5Tget_cset(type);
-
- printf("H5T_STRING %s\n", dump_header_format->strblockbegin);
- indent += COL;
-
- indentation(indent + COL);
- printf("%s %d;\n", STRSIZE, (int) size);
-
- indentation(indent + COL);
- printf("%s ", STRPAD);
- if (str_pad == H5T_STR_NULLTERM)
- printf("H5T_STR_NULLTERM;\n");
- else if (str_pad == H5T_STR_NULLPAD)
- printf("H5T_STR_NULLPAD;\n");
- else if (str_pad == H5T_STR_SPACEPAD)
- printf("H5T_STR_SPACEPAD;\n");
- else
- printf("H5T_STR_ERROR;\n");
-
- indentation(indent + COL);
- printf("%s ", CSET);
-
- if (cset == H5T_CSET_ASCII)
- printf("H5T_CSET_ASCII;\n");
- else
- printf("unknown_cset;\n");
-
- str_type = H5Tcopy(H5T_C_S1);
- H5Tset_cset(str_type, cset);
- H5Tset_size(str_type, size);
- H5Tset_strpad(str_type, str_pad);
-
- indentation(indent + COL);
- printf("%s ", CTYPE);
-
- if (H5Tequal(type, str_type)) {
- printf("H5T_C_S1;\n");
- H5Tclose(str_type);
- } else {
- H5Tclose(str_type);
- str_type = H5Tcopy(H5T_FORTRAN_S1);
- H5Tset_cset(str_type, cset);
- H5Tset_size(str_type, size);
- H5Tset_strpad(str_type, str_pad);
-
- if (H5Tequal(type, str_type)) {
- printf("H5T_FORTRAN_S1;\n");
- } else {
- printf("unknown_one_character_type;\n ");
- d_status = EXIT_FAILURE;
- }
-
- H5Tclose(str_type);
- }
-
- indent -= COL;
- indentation(indent + COL);
- printf("%s", dump_header_format->strblockend);
- break;
-
- case H5T_BITFIELD:
- if (H5Tequal(type, H5T_STD_B8BE)) {
- printf("H5T_STD_B8BE");
- } else if (H5Tequal(type, H5T_STD_B8LE)) {
- printf("H5T_STD_B8LE");
- } else if (H5Tequal(type, H5T_STD_B16BE)) {
- printf("H5T_STD_B16BE");
- } else if (H5Tequal(type, H5T_STD_B16LE)) {
- printf("H5T_STD_B16LE");
- } else if (H5Tequal(type, H5T_STD_B32BE)) {
- printf("H5T_STD_B32BE");
- } else if (H5Tequal(type, H5T_STD_B32LE)) {
- printf("H5T_STD_B32LE");
- } else if (H5Tequal(type, H5T_STD_B64BE)) {
- printf("H5T_STD_B64BE");
- } else if (H5Tequal(type, H5T_STD_B64LE)) {
- printf("H5T_STD_B64LE");
- } else {
- printf("undefined bitfield");
- d_status = EXIT_FAILURE;
- }
- break;
-
- case H5T_OPAQUE:
- printf("\n");
- indentation(indent + COL);
- printf("H5T_OPAQUE;\n");
- indentation(indent + COL);
- printf("OPAQUE_TAG \"%s\";\n", H5Tget_tag(type));
- indentation(indent);
- break;
-
- case H5T_COMPOUND:
- if (H5Tcommitted(type) > 0) {
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
- i = search_obj(type_table, statbuf.objno);
-
- if (i >= 0) {
- if (!type_table->objs[i].recorded)
- printf("\"/#%lu:%lu\"\n", type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- else
- printf("\"%s\"", type_table->objs[i].objname);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unknown committed type.\n");
- d_status = EXIT_FAILURE;
- }
- } else {
- nmembers = H5Tget_nmembers(type);
- printf("H5T_COMPOUND %s\n", dump_header_format->structblockbegin);
-
- for (i = 0; i < nmembers; i++) {
- fname = H5Tget_member_name(type, i);
- mtype = H5Tget_member_type(type, i);
-
- indentation(indent + COL);
-
- if (H5Tget_class(mtype) == H5T_COMPOUND)
- indent += COL;
-
- print_datatype(mtype);
-
- if (H5Tget_class(mtype) == H5T_COMPOUND)
- indent -= COL;
-
- printf(" \"%s\";\n", fname);
- free(fname);
- }
-
- indentation(indent);
- printf("%s", dump_header_format->structblockend);
- }
-
- break;
-
- case H5T_REFERENCE:
- printf("H5T_REFERENCE");
- break;
-
- case H5T_ENUM:
- printf("H5T_ENUM %s\n", dump_header_format->enumblockbegin);
- indent += COL;
- indentation(indent + COL);
- super = H5Tget_super(type);
- print_datatype(super);
- printf(";\n");
- print_enum(type);
- indent -= COL;
- indentation(indent + COL);
- printf("%s", dump_header_format->enumblockend);
- break;
-
- case H5T_VLEN:
- printf("H5T_VLEN %s ", dump_header_format->vlenblockbegin);
-
- super = H5Tget_super(type);
- print_datatype(super);
- H5Tclose(super);
-
- /* Print closing */
- printf("%s", dump_header_format->vlenblockend);
- break;
-
- case H5T_ARRAY:
- /* Get array base type */
- super = H5Tget_super(type);
-
- /* Print lead-in */
- printf("H5T_ARRAY { ");
-
- /* Get array information */
- ndims = H5Tget_array_ndims(type);
- H5Tget_array_dims(type, dims, perm);
-
- /* Print array dimensions */
- for (j = 0; j < ndims; j++)
- printf("[%d]", (int) dims[j]);
-
- printf(" ");
-
- /* Print base type */
- print_datatype(super);
-
- /* Close array base type */
- H5Tclose(super);
-
- /* Print closing */
- printf(" }");
-
- break;
-
- default:
- printf("unknown data type");
- d_status = EXIT_FAILURE;
- break;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_bb
- *
- * Purpose: Dump the boot block
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_bb(void)
-{
- printf("%s %s boot block not yet implemented %s\n",
- BOOT_BLOCK, BEGIN, END);
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_datatype
- *
- * Purpose: Dump the data type. Data type can be HDF5 predefined
- * atomic data type or committed/transient data type.
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_datatype(hid_t type)
-{
- indent += COL;
-
- indentation(indent);
- printf("%s %s ", dump_header_format->datatypebegin,
- dump_header_format->datatypeblockbegin);
-
- print_datatype(type);
-
- if (H5Tget_class(type) == H5T_COMPOUND || H5Tget_class(type) == H5T_STRING)
- indentation(indent);
-
- printf(" %s %s\n", dump_header_format->datatypeblockend,
- dump_header_format->datatypeend);
- indent -= COL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_dataspace
- *
- * Purpose: Dump the data space. Data space can be named data space,
- * array, or others.
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_dataspace(hid_t space)
-{
- hsize_t size[H5DUMP_MAX_RANK];
- hsize_t maxsize[H5DUMP_MAX_RANK];
- int ndims =
- H5Sget_simple_extent_dims(space, size, maxsize);
- int i;
-
- indentation(indent + COL);
- printf("%s ", dump_header_format->dataspacebegin);
-
- if (H5Sis_simple(space)) {
- if (ndims == 0) {
- /* scalar dataspace */
- HDfprintf(stdout, "%s %s ",
- dump_header_format->dataspacedescriptionbegin, SCALAR);
- } else {
- /* simple dataspace */
- HDfprintf(stdout, "%s %s { %s %Hu",
- dump_header_format->dataspacedescriptionbegin, SIMPLE,
- dump_header_format->dataspacedimbegin, size[0]);
-
- for (i = 1; i < ndims; i++)
- HDfprintf(stdout, ", %Hu", size[i]);
-
- printf(" %s / ", dump_header_format->dataspacedimend);
-
- if (maxsize[0] == H5S_UNLIMITED)
- HDfprintf(stdout, "%s %s",
- dump_header_format->dataspacedimbegin,
- "H5S_UNLIMITED");
- else
- HDfprintf(stdout, "%s %Hu",
- dump_header_format->dataspacedimbegin, maxsize[0]);
-
- for (i = 1; i < ndims; i++)
- if (maxsize[i] == H5S_UNLIMITED)
- HDfprintf(stdout, ", %s", "H5S_UNLIMITED");
- else
- HDfprintf(stdout, ", %Hu", maxsize[i]);
-
- printf(" %s }", dump_header_format->dataspacedimend);
- }
- } else {
- printf("%s not yet implemented %s\n", BEGIN, END);
- }
-
- end_obj(dump_header_format->dataspaceend,
- dump_header_format->dataspaceblockend);
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_attr
- *
- * Purpose: dump the attribute
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
-{
- hid_t attr_id, type, space;
- herr_t ret = SUCCEED;
-
- indentation(indent);
- begin_obj(dump_header_format->attributebegin, attr_name,
- dump_header_format->attributeblockbegin);
-
- if ((attr_id = H5Aopen_name(attr, attr_name)) >= 0) {
- type = H5Aget_type(attr_id);
- space = H5Aget_space(attr_id);
- dump_datatype(type);
- dump_dataspace(space);
-
- if (display_oid)
- dump_oid(attr_id);
-
- if (display_data)
- dump_data(attr_id, ATTRIBUTE_DATA);
-
- H5Tclose(type);
- H5Sclose(space);
- H5Aclose(attr_id);
- indentation(indent);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- } else {
- indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open attribute \"%s\"\n", attr_name);
- indentation(indent);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- ret = FAIL;
- }
-
- return ret;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_selected_attr
- *
- * Purpose: dump the selected attribute
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-dump_selected_attr(hid_t loc_id, const char *name)
-{
- int j;
- char *obj_name;
- const char *attr_name;
- hid_t oid, attr_id, type, space;
- H5G_stat_t statbuf;
-
- j = (int)strlen(name) - 1;
- obj_name = malloc((size_t)j + 2);
-
- /* find the last / */
- while (name[j] != '/' && j >= 0)
- j--;
-
- /* object name */
- if (j == -1) {
- strcpy(obj_name, "/");
- } else {
- strncpy(obj_name, name, (size_t)j + 1);
- obj_name[j+1] = '\0';
- }
-
- attr_name = name + j + 1;
- begin_obj(dump_header_format->attributebegin, name,
- dump_header_format->attributeblockbegin);
- H5Gget_objinfo(loc_id, obj_name, FALSE, &statbuf);
-
- switch (statbuf.type) {
- case H5G_GROUP:
- if ((oid = H5Gopen(loc_id, obj_name)) < 0) {
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open group \"%s\"\n", obj_name);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
-
- case H5G_DATASET:
- if ((oid = H5Dopen(loc_id, obj_name)) < 0) {
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open dataset \"%s\"\n", obj_name);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
-
- case H5G_TYPE:
- if ((oid = H5Topen(loc_id, obj_name)) < 0) {
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open datatype \"%s\"\n", obj_name);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
-
- default:
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open unknown \"%s\"\n", obj_name);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
-
- if ((attr_id = H5Aopen_name(oid, attr_name)) >= 0) {
- type = H5Aget_type(attr_id);
- space = H5Aget_space(attr_id);
- dump_datatype(type);
- dump_dataspace(space);
-
- if (display_oid)
- dump_oid(attr_id);
-
- if (display_data)
- dump_data(attr_id, ATTRIBUTE_DATA);
-
- H5Tclose(type);
- H5Sclose(space);
- H5Aclose(attr_id);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- } else {
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open attribute \"%s\"\n", obj_name);
- end_obj(dump_header_format->attributeend,
- dump_header_format->attributeblockend);
- d_status = EXIT_FAILURE;
- }
-
- switch (statbuf.type) {
- case H5G_GROUP:
- if (H5Gclose(oid) < 0) {
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
-
- case H5G_DATASET:
- if (H5Dclose(oid) < 0) {
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
-
- case H5G_TYPE:
- if (H5Tclose(oid) < 0) {
- d_status = EXIT_FAILURE;
- return FAIL;
- }
- break;
- default:
- d_status = EXIT_FAILURE;
- return FAIL;
- }
-
- free(obj_name);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_all
- *
- * Purpose: Dump everything in the specified object
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- * 11/00 Added XML support. Also, optionally checks the op_data
- * argument.
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-dump_all(hid_t group, const char *name, void * op_data)
-{
- hid_t obj;
- char *buf, *tmp, *tmp2;
- H5G_stat_t statbuf;
- int i;
-
- H5Gget_objinfo(group, name, FALSE, &statbuf);
- if ((*(int *)op_data != H5G_UNKNOWN) &&
- (statbuf.type != *(int *) op_data))
- return SUCCEED;
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
- strcpy(tmp, prefix);
-
- switch (statbuf.type) {
- case H5G_LINK:
- indentation(indent);
- buf = malloc(statbuf.linklen);
-
- if (!doxml) {
- begin_obj(dump_header_format->softlinkbegin, name,
- dump_header_format->softlinkblockbegin);
- indentation(indent + COL);
- }
-
- if (H5Gget_linkval(group, name, statbuf.linklen, buf) >= 0) {
- /* print the value of a soft link */
- if (!doxml) {
- /* Standard DDL: no modification */
- printf("LINKTARGET \"%s\"\n", buf);
- } else {
- /* XML */
- tmp2 = (char *) malloc(strlen(prefix) + statbuf.linklen + 2);
- strcpy(tmp2, prefix);
- if (buf && buf[0] == '/') {
- strcat(tmp2, buf);
- } else {
- strcat(strcat(tmp2, "/"), buf);
- }
- strcat(strcat(tmp, "/"), name);
- printf
- ("<SoftLink LinkName=\"%s\" Target=\"%s\" TargetObj=\"%s\" OBJ-XID=\"%s\" Source=\"%s\"/>\n",
- xml_escape_the_name(name),
- xml_escape_the_name(buf),
- xml_escape_the_name(tmp2),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
- free(tmp2);
- }
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get link value\n");
- d_status = EXIT_FAILURE;
- }
-
- if (!doxml) {
- indentation(indent);
- end_obj(dump_header_format->softlinkend,
- dump_header_format->softlinkblockend);
- }
-
- free(buf);
- break;
-
- case H5G_GROUP:
- if ((obj = H5Gopen(group, name)) >= 0) {
- strcat(strcat(prefix, "/"), name);
- dump_function_table->dump_group_function(obj, name);
- strcpy(prefix, tmp);
- H5Gclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump group \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
-
- break;
-
- case H5G_DATASET:
- if ((obj = H5Dopen(group, name)) >= 0) {
- /* hard link */
- H5Gget_objinfo(obj, ".", TRUE, &statbuf);
-
- if (statbuf.nlink > 1) {
- i = search_obj(dset_table, statbuf.objno);
-
- if (i < 0) {
- indentation(indent);
- begin_obj(dump_header_format->datasetbegin, name,
- dump_header_format->datasetblockbegin);
- indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
- indentation(indent);
- end_obj(dump_header_format->datasetend,
- dump_header_format->datasetblockend);
- d_status = EXIT_FAILURE;
- H5Dclose(obj);
- goto done;
- } else if (dset_table->objs[i].displayed) {
- indentation(indent);
- if (!doxml) {
- begin_obj(dump_header_format->datasetbegin, name,
- dump_header_format->datasetblockbegin);
- indentation(indent + COL);
- printf("%s \"%s\"\n", HARDLINK,
- dset_table->objs[i].objname);
- indentation(indent);
- end_obj(dump_header_format->datasetend,
- dump_header_format->datasetblockend);
- } else {
- /* the XML version */
- strcat(strcat(tmp, "/"), name);
- printf
- ("<Dataset Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix)
- : "root"));
-
- indentation(indent + COL);
- printf("<DatasetPtr OBJ-XID=\"%s\"/>\n",
- xml_escape_the_name(dset_table->objs[i].objname));
- indentation(indent);
- printf("%s\n", dump_header_format->datasetend);
- }
- H5Dclose(obj);
- goto done;
- } else {
- dset_table->objs[i].displayed = 1;
- strcat(tmp, "/");
- strcat(tmp, name);
- strcpy(dset_table->objs[i].objname, tmp);
- }
- }
-
- dump_function_table->dump_dataset_function(obj, name);
- H5Dclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump dataset \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
- break;
-
- case H5G_TYPE:
- if ((obj = H5Topen(group, name)) >= 0) {
- dump_function_table->dump_named_datatype_function(obj, name);
- H5Tclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump data type \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
-
- break;
-
- default:
- fflush(stdout);
- fprintf(stderr, "h5dump error: unknown object \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
-
- done:
- free(tmp);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_named_datatype
- *
- * Purpose: Dump named data type
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications: Comments: not yet implemented.
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_named_datatype(hid_t type, const char *name)
-{
- indentation(indent);
- printf("%s \"%s\" %s", dump_header_format->datatypebegin, name,
- dump_header_format->datatypeblockbegin);
-
- if (H5Tget_class(type) == H5T_COMPOUND) {
- hid_t temp_type = H5Tcopy(type);
-
- print_datatype(temp_type);
- H5Tclose(temp_type);
- } else {
- indentation(indent + COL);
- print_datatype(type);
- printf(";\n");
- }
-
- indentation(indent);
- end_obj(dump_header_format->datatypeend,
- dump_header_format->datatypeblockend);
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_group
- *
- * Purpose: Dump everything within the specified group
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- * Call to dump_all -- add parameter to select everything.
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_group(hid_t gid, const char *name)
-{
- H5G_stat_t statbuf;
- hid_t dset, type;
- char typename[1024], *tmp;
- int i;
- int xtype = H5G_UNKNOWN; /* dump all */
-
- tmp = malloc(strlen(prefix) + strlen(name) + 2);
- strcpy(tmp, prefix);
- indentation(indent);
- begin_obj(dump_header_format->groupbegin, name,
- dump_header_format->groupblockbegin);
- indent += COL;
-
- if (display_oid)
- dump_oid(gid);
-
- if (!strcmp(name, "/") && unamedtype)
- /* dump unamed type in root group */
- for (i = 0; i < type_table->nobjs; i++)
- if (!type_table->objs[i].recorded) {
- dset = H5Dopen(gid, type_table->objs[i].objname);
- type = H5Dget_type(dset);
- sprintf(typename, "#%lu:%lu",
- type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- dump_named_datatype(type, typename);
- H5Tclose(type);
- H5Dclose(dset);
- }
-
- H5Gget_objinfo(gid, ".", TRUE, &statbuf);
-
- if (statbuf.nlink > 1) {
- i = search_obj(group_table, statbuf.objno);
-
- if (i < 0) {
- indentation(indent);
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
- d_status = EXIT_FAILURE;
- } else if (group_table->objs[i].displayed) {
- indentation(indent);
- printf("%s \"%s\"\n", HARDLINK, group_table->objs[i].objname);
- } else {
- strcpy(group_table->objs[i].objname, prefix);
- group_table->objs[i].displayed = 1;
- H5Aiterate(gid, NULL, dump_attr, NULL);
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- }
- } else {
- H5Aiterate(gid, NULL, dump_attr, NULL);
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- }
-
- indent -= COL;
- indentation(indent);
- end_obj(dump_header_format->groupend, dump_header_format->groupblockend);
- free(tmp);
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_dataset
- *
- * Purpose: Dump the specified data set
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_dataset(hid_t did, const char *name)
-{
- hid_t type, space;
-
- indentation(indent);
- begin_obj(dump_header_format->datasetbegin, name,
- dump_header_format->datasetblockbegin);
- type = H5Dget_type(did);
- space = H5Dget_space(did);
- dump_datatype(type);
- dump_dataspace(space);
-
- if (display_oid)
- dump_oid(did);
-
- if (display_data)
- switch (H5Tget_class(type)) {
- case H5T_TIME:
- indentation(indent + COL);
- printf("DATA{ not yet implemented.}\n");
- break;
-
- case H5T_INTEGER:
- case H5T_FLOAT:
- case H5T_STRING:
- case H5T_BITFIELD:
- case H5T_OPAQUE:
- case H5T_COMPOUND:
- case H5T_REFERENCE:
- case H5T_ENUM:
- case H5T_VLEN:
- case H5T_ARRAY:
- dump_data(did, DATASET_DATA);
- break;
-
- default:
- break;
- }
-
- indent += COL;
- H5Aiterate(did, NULL, dump_attr, NULL);
- indent -= COL;
- H5Tclose(type);
- H5Sclose(space);
- indentation(indent);
- end_obj(dump_header_format->datasetend,
- dump_header_format->datasetblockend);
-}
-
-#if H5DUMP_DEBUG
-/*-------------------------------------------------------------------------
- * Function: dump_tables
- *
- * Purpose: display the contents of tables for debugging purposes
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_tables(void)
-{
- int i;
-
- printf("group_table: # of entries = %d\n", group_table->nobjs);
-
- for (i = 0; i < group_table->nobjs; i++)
- printf("%lu %lu %s %d %d\n", group_table->objs[i].objno[0],
- group_table->objs[i].objno[1],
- group_table->objs[i].objname,
- group_table->objs[i].displayed, group_table->objs[i].recorded);
-
- printf("\ndset_table: # of entries = %d\n", dset_table->nobjs);
-
- for (i = 0; i < dset_table->nobjs; i++)
- printf("%lu %lu %s %d %d\n", dset_table->objs[i].objno[0],
- dset_table->objs[i].objno[1],
- dset_table->objs[i].objname,
- dset_table->objs[i].displayed, dset_table->objs[i].recorded);
-
- printf("\ntype_table: # of entries = %d\n", type_table->nobjs);
-
- for (i = 0; i < type_table->nobjs; i++)
- printf("%lu %lu %s %d %d\n", type_table->objs[i].objno[0],
- type_table->objs[i].objno[1],
- type_table->objs[i].objname,
- type_table->objs[i].displayed, type_table->objs[i].recorded);
-}
-#endif /* H5DUMP_DEBUG */
-
-/*-------------------------------------------------------------------------
- * Function: dump_data
- *
- * Purpose: Dump attribute or dataset data
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_data(hid_t obj_id, int obj_data)
-{
- h5dump_t *outputformat = &dataformat;
- int status = -1;
- void *buf;
- hid_t space, type, p_type;
- int ndims, i;
- hsize_t size[64], nelmts = 1, alloc_size;
- int depth;
- int stdindent = COL; /* should be 3 */
-
- outputformat->line_ncols = nCols;
- indent += COL;
-
- /*
- * the depth will tell us how far we need to indent extra. we use to just
- * use indent but with the merging of the tools lib we have to do
- * something different for the lib funtions... the normal indentation is 6
- * so when we don't need any extra indentation, depth will be 0.
- */
- depth = indent / stdindent + 1;
- indentation(indent);
- begin_obj(dump_header_format->databegin, (const char *) NULL,
- dump_header_format->datablockbegin);
-
- /* Print all the values. */
- if (obj_data == DATASET_DATA) {
- status = h5dump_dset(stdout, outputformat, obj_id, -1, depth);
- } else {
- /* need to call h5dump_mem for the attribute data */
- type = H5Aget_type(obj_id);
- p_type = h5dump_fixtype(type);
- space = H5Aget_space(obj_id);
- ndims = H5Sget_simple_extent_dims(space, size, NULL);
-
- for (i = 0; i < ndims; i++)
- nelmts *= size[i];
-
- alloc_size = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
- assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
- buf = malloc((size_t)alloc_size);
- assert(buf);
-
- if (H5Aread(obj_id, p_type, buf) >= 0)
- status = h5dump_mem(stdout, outputformat, obj_id, p_type, space, buf, depth);
-
- free(buf);
- H5Tclose(p_type);
- H5Sclose(space);
- H5Tclose(type);
- }
-
- if (status < 0) {
- indentation(indent + COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to print data\n");
- d_status = EXIT_FAILURE;
- }
-
- indentation(indent);
- end_obj(dump_header_format->dataend, dump_header_format->datablockend);
- indent -= COL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_oid
- *
- * Purpose: Prints the object ids
- *
- * Return: void
- *
- * Programmer: Patrick Lu
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-dump_oid(hid_t oid)
-{
- indentation(indent + COL);
- printf("%s %s %d %s\n", OBJID, BEGIN, oid, END);
-}
-
-/*-------------------------------------------------------------------------
- * Function: set_output_file
- *
- * Purpose: Open fname as the output file for dataset raw data.
- * Set rawdatastream as its file stream.
- *
- * Return: 0 -- succeeded
- * negative -- failed
- *
- * Programmer: Albert Cheng, 2000/09/30
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-set_output_file(const char *fname)
-{
- FILE *f; /* temporary holding place for the stream pointer
- so that rawdatastream is changed only when succeeded */
-
- if ((f = fopen(fname, "w")) != NULL) {
- rawdatastream = f;
- return 0;
- }
-
- return -1;
-}
-
-/*-------------------------------------------------------------------------
- * Function: handle_attributes
- *
- * Purpose: Handle the attributes from the command.
- *
- * Return: void
- *
- * Programmer: Bill Wendling
- * Tuesday, 9. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-handle_attributes(hid_t fid, char *attr)
-{
- dump_selected_attr(fid, attr);
-}
-
-/*-------------------------------------------------------------------------
- * Function: parse_hsize_list
- *
- * Purpose: Parse a list of comma or space separated integers and return
- * them in a list. The string being passed into this function
- * should be at the start of the list you want to parse. You are
- * responsible for freeing the array returned from here.
- *
- * Lists in the so-called "terse" syntax are separated by
- * semicolons (;). The lists themselves can be separated by
- * either commas (,) or white spaces.
- *
- * Return: Success: hsize_t array. NULL is a valid return type if
- * there aren't any elements in the array.
- *
- * Programmer: Bill Wendling
- * Tuesday, 6. February 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hsize_t *
-parse_hsize_list(const char *h_list)
-{
- hsize_t *p_list;
- const char *ptr;
- unsigned int size_count = 0, i = 0, last_digit = 0;
-
- if (!h_list || !*h_list || *h_list == ';')
- return NULL;
-
- /* count how many integers do we have */
- for (ptr = h_list; ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++)
- if (isdigit(*ptr)) {
- if (!last_digit)
- /* the last read character wasn't a digit */
- size_count++;
-
- last_digit = 1;
- } else {
- last_digit = 0;
- }
-
- if (size_count == 0)
- /* there aren't any integers to read */
- return NULL;
-
- /* allocate an array for the integers in the list */
- p_list = calloc(size_count, sizeof(hsize_t));
-
- for (ptr = h_list; i < size_count && ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++)
- if (isdigit(*ptr)) {
- /* we should have an integer now */
- p_list[i++] = (hsize_t)atoi(ptr);
-
- while (isdigit(*ptr))
- /* scroll to end of integer */
- ptr++;
- }
-
- return p_list;
-}
-
-/*-------------------------------------------------------------------------
- * Function: parse_subset_params
- *
- * Purpose: Parse the so-called "terse" syntax for specifying subsetting
- * parameters.
- *
- * Return: Success: struct subset_t object
- * Failure: NULL
- *
- * Programmer: Bill Wendling
- * Tuesday, 6. February 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static struct subset_t *
-parse_subset_params(char *dset)
-{
- struct subset_t *s = NULL;
- register char *brace;
-
- if ((brace = strrchr(dset, '[')) != NULL) {
- char *slash = strrchr(dset, '/');
-
- /* sanity check to make sure the [ isn't part of the dataset name */
- if (brace > slash) {
- *brace++ = '\0';
- s = calloc(1, sizeof(struct subset_t));
-
- printf("start\n");
- s->start = parse_hsize_list(brace);
-
- while (*brace && *brace != ';')
- brace++;
-
- if (*brace)
- brace++;
-
- printf("stride\n");
- s->stride = parse_hsize_list(brace);
-
- while (*brace && *brace != ';')
- brace++;
-
- if (*brace)
- brace++;
-
- printf("count\n");
- s->count = parse_hsize_list(brace);
-
- while (*brace && *brace != ';')
- brace++;
-
- if (*brace)
- brace++;
-
- printf("block\n");
- s->block = parse_hsize_list(brace);
- }
- }
-
- return s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: handle_datasets
- *
- * Purpose: Handle the datasets from the command.
- *
- * Return: void
- *
- * Programmer: Bill Wendling
- * Tuesday, 9. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-handle_datasets(hid_t fid, char *dset)
-{
- H5G_stat_t statbuf;
- hid_t dsetid;
-
- if ((dsetid = H5Dopen(fid, dset)) < 0) {
- begin_obj(dump_header_format->datasetbegin, dset,
- dump_header_format->datasetblockbegin);
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open dataset \"%s\"\n", dset);
- end_obj(dump_header_format->datasetend,
- dump_header_format->datasetblockend);
- d_status = EXIT_FAILURE;
- } else {
- H5Gget_objinfo(dsetid, ".", TRUE, &statbuf);
-
- if (statbuf.nlink > 1) {
- int index = search_obj(dset_table, statbuf.objno);
-
- if (index >= 0) {
- if (dset_table->objs[index].displayed) {
- begin_obj(dump_header_format->datasetbegin, dset,
- dump_header_format->datasetblockbegin);
- indentation(indent + COL);
- printf("%s \"%s\"\n", HARDLINK,
- dset_table->objs[index].objname);
- indentation(indent);
- end_obj(dump_header_format->datasetend,
- dump_header_format->datasetblockend);
- } else {
- strcpy(dset_table->objs[index].objname, dset);
- dset_table->objs[index].displayed = 1;
- dump_dataset(dsetid, dset);
- }
- } else {
- d_status = EXIT_FAILURE;
- }
- } else {
- dump_dataset(dsetid, dset);
- }
-
- if (H5Dclose(dsetid) < 1)
- d_status = EXIT_FAILURE;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: handle_groups
- *
- * Purpose: Handle the groups from the command.
- *
- * Return: void
- *
- * Programmer: Bill Wendling
- * Tuesday, 9. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-handle_groups(hid_t fid, char *group)
-{
- H5G_stat_t statbuf;
- hid_t gid;
-
- if ((gid = H5Gopen(fid, group)) < 0) {
- begin_obj(dump_header_format->groupbegin, group,
- dump_header_format->groupblockbegin);
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open group \"%s\"\n", group);
- end_obj(dump_header_format->groupend,
- dump_header_format->groupblockend);
- d_status = EXIT_FAILURE;
- } else {
- H5Gget_objinfo(gid, ".", TRUE, &statbuf);
- strcpy(prefix, group);
- dump_group(gid, group);
-
- if (H5Gclose(gid) < 0)
- d_status = EXIT_FAILURE;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: handle_links
- *
- * Purpose: Handle the links from the command.
- *
- * Return: void
- *
- * Programmer: Bill Wendling
- * Tuesday, 9. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-handle_links(hid_t fid, char *links)
-{
- H5G_stat_t statbuf;
-
- if (H5Gget_objinfo(fid, links, FALSE, &statbuf) < 0) {
- begin_obj(dump_header_format->softlinkbegin, links,
- dump_header_format->softlinkblockbegin);
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get obj info from \"%s\"\n", links);
- end_obj(dump_header_format->softlinkend,
- dump_header_format->softlinkblockend);
- d_status = EXIT_FAILURE;
- } else if (statbuf.type == H5G_LINK) {
- char *buf = malloc(statbuf.linklen);
-
- begin_obj(dump_header_format->softlinkbegin, links,
- dump_header_format->softlinkblockbegin);
- indentation(COL);
-
- if (H5Gget_linkval(fid, links, statbuf.linklen, buf) >= 0) {
- printf("LINKTARGET \"%s\"\n", buf);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get link value for \"%s\"\n",
- links);
- d_status = EXIT_FAILURE;
- }
-
- end_obj(dump_header_format->softlinkend,
- dump_header_format->softlinkblockend);
- free(buf);
- } else {
- begin_obj(dump_header_format->softlinkbegin, links,
- dump_header_format->softlinkblockbegin);
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: \"%s\" is not a link\n", links);
- end_obj(dump_header_format->softlinkend,
- dump_header_format->softlinkblockend);
- d_status = EXIT_FAILURE;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: handle_datatypes
- *
- * Purpose: Handle the datatypes from the command.
- *
- * Return: void
- *
- * Programmer: Bill Wendling
- * Tuesday, 9. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-handle_datatypes(hid_t fid, char *type)
-{
- hid_t typeid;
-
- if ((typeid = H5Topen(fid, type)) < 0) {
- /* check if type is unamed data type */
- int index = 0;
-
- while (index < type_table->nobjs ) {
- char name[128], name1[128];
-
- if (!type_table->objs[index].recorded) {
- /* unamed data type */
- sprintf(name, "#%lu:%lu\n",
- type_table->objs[index].objno[0],
- type_table->objs[index].objno[1]);
- sprintf(name1, "/#%lu:%lu\n",
- type_table->objs[index].objno[0],
- type_table->objs[index].objno[1]);
-
- if (!strncmp(name, type, strlen(type)) ||
- !strncmp(name1, type, strlen(type)))
- break;
- }
-
- index++;
- }
-
- if (index == type_table->nobjs) {
- /* unknown type */
- begin_obj(dump_header_format->datatypebegin, type,
- dump_header_format->datatypeblockbegin);
- indentation(COL);
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open datatype \"%s\"\n", type);
- end_obj(dump_header_format->datatypeend,
- dump_header_format->datatypeblockend);
- d_status = EXIT_FAILURE;
- } else {
- hid_t dsetid = H5Dopen(fid, type_table->objs[index].objname);
- typeid = H5Dget_type(dsetid);
- dump_named_datatype(typeid, type);
- H5Tclose(typeid);
- H5Dclose(dsetid);
- }
- } else {
- dump_named_datatype(typeid, type);
-
- if (H5Tclose(typeid) < 0)
- d_status = EXIT_FAILURE;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: HDF5 dumper
- *
- * Return: Success: 0
- * Failure: 1
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- * Albert Cheng, 30. September 2000
- * Add the -o option--output file for datasets raw data
- *
- * REMcG, November 2000
- * Changes to support XML.
- *
- * Bill Wendling
- * Wednesday, 10. January 2001
- * Modified the way command line parameters are interpreted. They go
- * through one function call now (get_option).
- *
- *-------------------------------------------------------------------------
- */
-int
-main(int argc, const char *argv[])
-{
- hid_t fid, gid;
- const char *progname = "h5dump";
- const char *fname = NULL;
- int i, display_bb = 0, display_all = 1, newwidth = 0;
- void *edata;
- hid_t (*func)(void*);
- find_objs_t info;
- int opt;
- struct handler_t *hand, *last_dset;
- int usingdasho = FALSE, last_was_dset = FALSE;
-
- if (argc < 2) {
- usage(progname);
- exit(EXIT_FAILURE);
- }
-
- dump_header_format = &standardformat;
- dump_function_table = &ddl_function_table;
-
- /* Disable error reporting */
- H5Eget_auto(&func, &edata);
- H5Eset_auto(NULL, NULL);
-
- /* Initialize h5tools lib */
- h5tools_init();
-
- /* this will be plenty big enough to hold the info */
- hand = calloc((size_t)argc, sizeof(struct handler_t));
-
- /* parse command line options */
- while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
-parse_start:
- switch ((char)opt) {
- case 'B':
- display_bb = TRUE;
- last_was_dset = FALSE;
- break;
- case 'H':
- display_data = FALSE;
- last_was_dset = FALSE;
- break;
- case 'v':
- display_oid = TRUE;
- last_was_dset = FALSE;
- break;
- case 'V':
- print_version(progname);
- exit(EXIT_SUCCESS);
- break;
- case 'w':
- nCols = atoi(opt_arg);
- last_was_dset = FALSE;
- break;
- case 'a':
- display_all = 0;
-
- for (i = 0; i < argc; i++)
- if (!hand[i].func) {
- hand[i].func = handle_attributes;
- hand[i].obj = strdup(opt_arg);
- break;
- }
-
- last_was_dset = FALSE;
- break;
- case 'd':
- display_all = 0;
-
- for (i = 0; i < argc; i++)
- if (!hand[i].func) {
- hand[i].func = handle_datasets;
- hand[i].obj = strdup(opt_arg);
- hand[i].subset_info = parse_subset_params(hand[i].obj);
- last_dset = hand;
- break;
- }
-
- last_was_dset = TRUE;
- break;
- case 'g':
- display_all = 0;
-
- for (i = 0; i < argc; i++)
- if (!hand[i].func) {
- hand[i].func = handle_groups;
- hand[i].obj = strdup(opt_arg);
- break;
- }
-
- last_was_dset = FALSE;
- break;
- case 'l':
- display_all = 0;
-
- for (i = 0; i < argc; i++)
- if (!hand[i].func) {
- hand[i].func = handle_links;
- hand[i].obj = strdup(opt_arg);
- break;
- }
-
- last_was_dset = FALSE;
- break;
- case 't':
- display_all = 0;
-
- for (i = 0; i < argc; i++)
- if (!hand[i].func) {
- hand[i].func = handle_datatypes;
- hand[i].obj = strdup(opt_arg);
- break;
- }
-
- last_was_dset = FALSE;
- break;
- case 'o':
- if (set_output_file(opt_arg) < 0){
- /* failed to set output file */
- usage(progname);
- exit(EXIT_FAILURE);
- }
-
- usingdasho = TRUE;
- last_was_dset = FALSE;
- break;
-
- /** XML parameters **/
- case 'x':
- /* select XML output */
- doxml = TRUE;
- dump_header_format = &xmlformat;
- dump_function_table = &xml_function_table;
- break;
- case 'D':
- /* specify alternative XML DTD */
- xml_dtd_uri = opt_arg;
- break;
- /** end XML parameters **/
-
- /** subsetting parameters **/
- case 's':
- case 'T':
- case 'c':
- case 'k': {
- struct subset_t *s;
-
- if (!last_was_dset) {
- fprintf(stderr, "%s error: option `-%c' can only be used after --dataset option\n",
- progname, opt);
- exit(EXIT_FAILURE);
- }
-
- if (last_dset->subset_info) {
- /* this overrides the "terse" syntax if they actually mixed
- * the two */
- s = last_dset->subset_info;
- } else {
- last_dset->subset_info = s = calloc(1, sizeof(struct subset_t));
- }
-
- /*
- * slightly convoluted, but...we are only interested in options
- * for subsetting: "--start", "--stride", "--count", and "--block"
- * which can come in any order. If we run out of parameters (EOF)
- * or run into one which isn't a subsetting parameter (NOT s, T,
- * c, or K), then we exit the do-while look, set hte subset_info
- * to the structure we've been filling. If we've reached the end
- * of the options, we exit the parsing (goto parse_end) otherwise,
- * since we've "read" the next option, we need to parse it. So we
- * just to the beginning of the switch statement (goto parse_start).
- */
- do {
- switch ((char)opt) {
- case 's': free(s->start); s->start = parse_hsize_list(opt_arg); break;
- case 'T': free(s->stride); s->stride = parse_hsize_list(opt_arg); break;
- case 'c': free(s->count); s->count = parse_hsize_list(opt_arg); break;
- case 'k': free(s->block); s->block = parse_hsize_list(opt_arg); break;
- default: goto end_collect;
- }
- } while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF);
-
-end_collect:
- last_was_dset = FALSE;
-
- if (opt != EOF)
- goto parse_start;
- else
- goto parse_end;
- }
- /** end subsetting parameters **/
-
- case 'h':
- usage(progname);
- exit(EXIT_SUCCESS);
- case '?':
- default:
- usage(progname);
- exit(EXIT_FAILURE);
- }
- }
-
-parse_end:
- /* check for conflicting options */
- if (doxml) {
- if (!display_all) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "to display selected objects");
- exit(EXIT_FAILURE);
- } else if (display_bb) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--boot-block");
- exit(EXIT_FAILURE);
- } else if (!display_data) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--header");
- exit(EXIT_FAILURE);
- } else if (display_oid == 1) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--object-ids");
- exit(EXIT_FAILURE);
- } else if (usingdasho) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: option \"%s\" not available for XML\n",
- "--output");
- exit(EXIT_FAILURE);
- }
- } else {
- if (xml_dtd_uri != NULL) {
- fflush(stdout);
- fprintf(stderr,
- "h5dump warning: option \"%s\" only applies with XML: %s\n",
- "--xml-dtd", xml_dtd_uri);
- }
- }
-
- if (argv[argc - 1][0] == '\\')
- fname = &argv[opt_ind][1];
- else
- fname = argv[opt_ind];
-
- fid = h5dump_fopen(fname, NULL, 0);
-
- if (fid < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open file \"%s\"\n", fname);
- exit(EXIT_FAILURE);
- }
-
- /* allocate and initialize internal data structure */
- init_table(&group_table);
- init_table(&type_table);
- init_table(&dset_table);
- init_prefix(&prefix, prefix_len);
-
- /* init the find_objs_t */
- info.threshold = 0;
- info.prefix_len = prefix_len;
- info.prefix = calloc((size_t)info.prefix_len, 1);
- info.group_table = group_table;
- info.type_table = type_table;
- info.dset_table = dset_table;
- info.status = d_status;
-
- if (doxml) {
- /* initialize XML */
- thefile = fid;
-
- /* find all objects that might be targets of a refernce */
- if ((gid = H5Gopen(fid, "/")) < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open root group\n");
- d_status = EXIT_FAILURE;
- goto done;
- }
-
- ref_path_table_put(gid, "/");
- H5Giterate(fid, "/", NULL, fill_ref_path_table, NULL);
- H5Gclose(gid);
-
- /* reset prefix! */
- strcpy(prefix, "");
-
- /* make sure the URI is initialized to something */
- if (xml_dtd_uri == NULL)
- xml_dtd_uri = DEFAULT_DTD;
- }
-
- /* find all shared objects */
- H5Giterate(fid, "/", NULL, find_objs, (void *)&info);
-
- /* does there exist unamed committed data type */
- for (i = 0; i < type_table->nobjs; i++)
- if (type_table->objs[i].recorded == 0)
- unamedtype = 1;
-
-#ifdef H5DUMP_DEBUG
- dump_tables();
-#endif /* H5DUMP_DEBUG */
-
- if (info.status) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
- d_status = EXIT_FAILURE;
- goto done;
- }
-
- /* start to dump */
- if (!doxml) {
- begin_obj(dump_header_format->filebegin, fname,
- dump_header_format->fileblockbegin);
- } else {
- printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- printf("<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n",
- xml_dtd_uri);
- printf("<HDF5-File>\n");
- }
-
- if (display_bb)
- dump_bb();
-
- if (newwidth)
- sscanf(argv[newwidth + 1], "%d", &nCols);
-
- if (display_all) {
- if ((gid = H5Gopen (fid, "/")) < 0 ) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to open root group\n");
- d_status = EXIT_FAILURE;
- } else {
- dump_function_table->dump_group_function(gid, "/");
- }
-
- if (H5Gclose (gid) < 0) {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to close root group\n");
- d_status = EXIT_FAILURE;
- }
- } else {
- if (doxml) {
- /* Note: this option is not supported for XML */
- fflush(stdout);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
- d_status = EXIT_FAILURE;
- goto done;
- }
-
- for (i = 0; i < argc; i++)
- if (hand[i].func)
- hand[i].func(fid, hand[i].obj);
- }
-
- if (!doxml) {
- end_obj(dump_header_format->fileend,
- dump_header_format->fileblockend);
- } else {
- printf("%s\n", dump_header_format->fileend);
- }
-
-done:
- if (H5Fclose(fid) < 0)
- d_status = EXIT_FAILURE;
-
- for (i = 0; i < argc; i++) {
- free(hand[i].obj);
-
- if (hand[i].subset_info) {
- free(hand[i].subset_info->start);
- free(hand[i].subset_info->stride);
- free(hand[i].subset_info->count);
- free(hand[i].subset_info->block);
- free(hand[i].subset_info);
- }
- }
-
- free(hand);
-
- free(group_table->objs);
- free(dset_table->objs);
- free(type_table->objs);
- free(prefix);
- free(info.prefix);
-
- /* To Do: clean up XML table */
-
- h5tools_close();
- H5Eset_auto(func, edata);
- return d_status;
-}
-
-/*-------------------------------------------------------------------------
- * Function: print_enum
- *
- * Purpose: prints the enum data -
- *
- * Return: void
- *
- * Programmer: Patrick Lu
- *
- * Modifications:
- *
- * NOTE: this function was taken from h5ls. should be moved into the toolslib
- *
- *-----------------------------------------------------------------------*/
-static void
-print_enum(hid_t type)
-{
- char **name = NULL; /*member names */
- unsigned char *value = NULL; /*value array */
- int nmembs; /*number of members */
- int nchars; /*number of output characters */
- hid_t super; /*enum base integer type */
- hid_t native = -1; /*native integer data type */
- size_t dst_size; /*destination value type size */
- int i;
-
- nmembs = H5Tget_nmembers(type);
- super = H5Tget_super(type);
-
- /*
- * Determine what data type to use for the native values. To simplify
- * things we entertain three possibilities:
- * 1. long_long -- the largest native signed integer
- * 2. unsigned long_long -- the largest native unsigned integer
- * 3. raw format
- */
- if (H5Tget_size(type) <= sizeof(long_long)) {
- dst_size = sizeof(long_long);
-
- if (H5T_SGN_NONE == H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
- }
- } else {
- dst_size = H5Tget_size(type);
- }
-
- /* Get the names and raw values of all members */
- assert(nmembs>0);
- name = calloc((size_t)nmembs, sizeof(char *));
- value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
-
- for (i = 0; i < nmembs; i++) {
- name[i] = H5Tget_member_name(type, i);
- H5Tget_member_value(type, i, value + i * H5Tget_size(type));
- }
-
- /* Convert values to native data type */
- if (native > 0)
- H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
-
- /*
- * Sort members by increasing value
- * ***not implemented yet***
- */
-
- /* Print members */
- for (i = 0; i < nmembs; i++) {
- indentation(indent + COL);
- nchars = printf("\"%s\"", name[i]);
- printf("%*s ", MAX(0, 16 - nchars), "");
-
- if (native < 0) {
- size_t j;
-
- printf("0x");
-
- for (j = 0; j < dst_size; j++)
- printf("%02x", value[i * dst_size + j]);
- } else if (H5T_SGN_NONE == H5Tget_sign(native)) {
- printf("%" PRINTF_LL_WIDTH "u", *((unsigned long_long *)
- ((void *) (value + i * dst_size))));
- } else {
- printf("%" PRINTF_LL_WIDTH "d",
- *((long_long *) ((void *) (value + i * dst_size))));
- }
-
- printf(";\n");
- }
-
- /* Release resources */
- for (i = 0; i < nmembs; i++)
- free(name[i]);
-
- free(name);
- free(value);
- H5Tclose(super);
-
- if (0 == nmembs)
- printf("\n%*s <empty>", indent + 4, "");
-}
-
-/*
- * XML support
- */
-
-/*
- * XML needs a table to look up a path name for an object
- * reference.
- *
- * This table stores mappings of reference -> path
- * for all objects in the file that may be the target of
- * an object reference.
- *
- * The 'path' is an absolute path by which the object
- * can be accessed. When an object has > 1 such path,
- * only one will be used in the table, with no particular
- * method of selecting which one.
- */
-
-struct ref_path_table_entry_t {
- hsize_t obj;
- hobj_ref_t *obj_ref;
- char *apath;
- struct ref_path_table_entry_t *next;
-};
-
-struct ref_path_table_entry_t *ref_path_table = NULL; /* the table */
-int npte = 0; /* number of entries in the table */
-
-/*-------------------------------------------------------------------------
- * Function: ref_path_table_lookup
- *
- * Purpose: Looks up a table entry given a path name.
- * Used during construction of the table.
- *
- * Return: The table entre (pte) or NULL if not in the
- * table.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static struct ref_path_table_entry_t *
-ref_path_table_lookup(const char *thepath)
-{
- int i;
- hobj_ref_t *ref;
- herr_t status;
- struct ref_path_table_entry_t *pte = ref_path_table;
-
- if (ref_path_table == NULL)
- return NULL;
-
- ref = (hobj_ref_t *) malloc(sizeof(hobj_ref_t));
-
- if (ref == NULL) {
- /* fatal error ? */
- return NULL;
- }
-
- status = H5Rcreate(ref, thefile, thepath, H5R_OBJECT, -1);
-
- if (status < 0) {
- /* fatal error ? */
- return NULL;
- }
-
- for (i = 0; i < npte; i++) {
- if (memcmp(ref, pte->obj_ref, sizeof(hobj_ref_t)) == 0) {
- return pte;
- }
-
- pte = pte->next;
- }
-
- return NULL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: ref_path_table_put
- *
- * Purpose: Enter the 'obj' with 'path' in the table if
- * not already there.
- * Create an object reference, pte, and store them
- * in the table.
- *
- * Return: The object reference for the object.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hobj_ref_t *
-ref_path_table_put(hid_t obj, const char *path)
-{
- hobj_ref_t *ref;
- herr_t status;
- struct ref_path_table_entry_t *pte;
-
- /* look up 'obj'. If already in table, return */
- pte = ref_path_table_lookup(path);
- if (pte != NULL)
- return pte->obj_ref;
-
- /* if not found, then make new entry */
-
- pte = (struct ref_path_table_entry_t *)
- malloc(sizeof(struct ref_path_table_entry_t));
- if (pte == NULL) {
- /* fatal error? */
- return NULL;
- }
-
- pte->obj = obj;
- ref = (hobj_ref_t *) malloc(sizeof(hobj_ref_t));
- if (ref == NULL) {
- /* fatal error? */
- free(pte);
- return NULL;
- }
-
- status = H5Rcreate(ref, thefile, path, H5R_OBJECT, -1);
- if (status < 0) {
- /* fatal error? */
- free(ref);
- free(pte);
- return NULL;
- }
-
- pte->obj_ref = ref;
-
- pte->apath = strdup(path);
-
- pte->next = ref_path_table;
- ref_path_table = pte;
-
- npte++;
-
- return ref;
-}
-
-/*-------------------------------------------------------------------------
- * Function: lookup_ref_path
- *
- * Purpose: Lookup the path to the object with refernce 'ref'.
- *
- * Return: Return a path to the object, or NULL if not found.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-lookup_ref_path(hobj_ref_t * ref)
-{
- int i;
- struct ref_path_table_entry_t *pte = NULL;
-
- if (ref_path_table == NULL)
- return NULL;
-
- pte = ref_path_table;
- if (pte == NULL) {
- /* fatal -- not initialized? */
- return NULL;
- }
- for (i = 0; i < npte; i++) {
- if (memcmp(ref, pte->obj_ref, sizeof(hobj_ref_t)) == 0) {
- return pte->apath;
- }
- pte = pte->next;
- }
- return NULL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: fill_ref_path_table
- *
- * Purpose: Called by interator to create references for
- * all objects and enter them in the table.
- *
- * Return: Error status.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-fill_ref_path_table(hid_t group, const char *name, void UNUSED * op_data)
-{
- hid_t obj;
- char *tmp;
- H5G_stat_t statbuf;
- struct ref_path_table_entry_t *pte;
- char *thepath;
-
- H5Gget_objinfo(group, name, FALSE, &statbuf);
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
- if (tmp == NULL)
- return FAIL;
- thepath = (char *) malloc(strlen(prefix) + strlen(name) + 2);
- if (thepath == NULL) {
- free(tmp);
- return FAIL;
- }
- strcpy(tmp, prefix);
-
- strcpy(thepath, prefix);
- strcat(thepath, "/");
- strcat(thepath, name);
-
- switch (statbuf.type) {
- case H5G_DATASET:
- if ((obj = H5Dopen(group, name)) >= 0) {
- pte = ref_path_table_lookup(thepath);
- if (pte == NULL) {
- ref_path_table_put(obj, thepath);
- }
- H5Dclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get dataset \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
- break;
- case H5G_GROUP:
- if ((obj = H5Gopen(group, name)) >= 0) {
- strcat(strcat(prefix, "/"), name);
- pte = ref_path_table_lookup(thepath);
- if (pte == NULL) {
- ref_path_table_put(obj, thepath);
- H5Giterate(obj, ".", NULL, fill_ref_path_table, NULL);
- strcpy(prefix, tmp);
- }
- H5Gclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to dump group \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
- break;
- case H5G_TYPE:
- if ((obj = H5Topen(group, name)) >= 0) {
- pte = ref_path_table_lookup(thepath);
- if (pte == NULL) {
- ref_path_table_put(obj, thepath);
- }
- H5Tclose(obj);
- } else {
- fflush(stdout);
- fprintf(stderr, "h5dump error: unable to get dataset \"%s\"\n", name);
- d_status = EXIT_FAILURE;
- }
- break;
- default:;
- }
- free(tmp);
- free(thepath);
- return 0;
-}
-
-static const char *quote = "&quot;";
-static const char *amp = "&amp;";
-static const char *lt = "&lt;";
-static const char *gt = "&gt;";
-static const char *apos = "&apos;";
-
-/*-------------------------------------------------------------------------
- * Function: xml_escape_the_name
- *
- * Purpose: Escape XML reserved chars in a name, so HDF5 strings
- * and paths can be correctly read back in XML element.
- *
- * Return: The revised string.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-xml_escape_the_name(const char *str)
-{
- int extra;
- int len;
- int i;
- const char *cp;
- char *ncp;
- char *rcp;
-
- if (str == NULL)
- return NULL;
-
- cp = str;
- len = strlen(str);
- extra = 0;
-
- for (i = 0; i < len; i++) {
- if (*cp == '\"') {
- extra += (strlen(quote) - 1);
- } else if (*cp == '\'') {
- extra += (strlen(apos) - 1);
- } else if (*cp == '<') {
- extra += (strlen(lt) - 1);
- } else if (*cp == '>') {
- extra += (strlen(gt) - 1);
- } else if (*cp == '&') {
- extra += (strlen(amp) - 1);
- }
- cp++;
- }
-
- if (extra == 0) {
- return (char *) str;
- } else {
- cp = str;
- rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
- if (ncp == NULL)
- return NULL; /* ?? */
- for (i = 0; i < len; i++) {
- if (*cp == '\'') {
- strncpy(ncp, apos, strlen(apos));
- ncp += strlen(apos);
- cp++;
- } else if (*cp == '<') {
- strncpy(ncp, lt, strlen(lt));
- ncp += strlen(lt);
- cp++;
- } else if (*cp == '>') {
- strncpy(ncp, gt, strlen(gt));
- ncp += strlen(gt);
- cp++;
- } else if (*cp == '\"') {
- strncpy(ncp, quote, strlen(quote));
- ncp += strlen(quote);
- cp++;
- } else if (*cp == '&') {
- strncpy(ncp, amp, strlen(amp));
- ncp += strlen(amp);
- cp++;
- } else {
- *ncp++ = *cp++;
- }
- }
- *ncp = '\0';
- return rcp;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_escape_the_string
- *
- * Purpose: Escape XML reserved chars in a string, so HDF5 strings
- * and paths can be correctly read back in XML CDATA.
- *
- * Return: The revised string.
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-xml_escape_the_string(const char *str, int slen)
-{
- int extra;
- int len;
- int i;
- const char *cp;
- char *ncp;
- char *rcp;
-
- if (str == NULL)
- return NULL;
-
- cp = str;
- if (slen < 0) {
- len = strlen(str);
- } else {
- len = slen;
- }
- extra = 0;
- for (i = 0; i < len; i++) {
- if (*cp == '\\') {
- extra++;
- } else if (*cp == '\"') {
- extra++;
- } else if (*cp == '\'') {
- extra += (strlen(apos) - 1);
- } else if (*cp == '<') {
- extra += (strlen(lt) - 1);
- } else if (*cp == '>') {
- extra += (strlen(gt) - 1);
- } else if (*cp == '&') {
- extra += (strlen(amp) - 1);
- }
- cp++;
- }
-
- cp = str;
- rcp = ncp = calloc((size_t)(len + extra + 1), sizeof(char));
- if (ncp == NULL)
- return NULL; /* ?? */
- for (i = 0; i < len; i++) {
- if (*cp == '\\') {
- *ncp++ = '\\';
- *ncp++ = *cp++;
- } else if (*cp == '\"') {
- *ncp++ = '\\';
- *ncp++ = *cp++;
- } else if (*cp == '\'') {
- strncpy(ncp, apos, strlen(apos));
- ncp += strlen(apos);
- cp++;
- } else if (*cp == '<') {
- strncpy(ncp, lt, strlen(lt));
- ncp += strlen(lt);
- cp++;
- } else if (*cp == '>') {
- strncpy(ncp, gt, strlen(gt));
- ncp += strlen(gt);
- cp++;
- } else if (*cp == '&') {
- strncpy(ncp, amp, strlen(amp));
- ncp += strlen(amp);
- cp++;
- } else {
- *ncp++ = *cp++;
- }
- }
- *ncp = '\0';
- return rcp;
-}
-
-/**
- ** XML print functions--these replace some functions in the
- ** h5tools.c suite.
- **/
-
-/*-------------------------------------------------------------------------
- * Function: xml_print_datatype
- *
- * Purpose: Print description of a datatype in XML.
- * Note: this is called inside a <DataType> element.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_print_datatype(hid_t type)
-{
- char *fname;
- hid_t nmembers, mtype;
- int i, j, ndims, perm[H5DUMP_MAX_RANK];
- size_t size;
- hsize_t dims[H5DUMP_MAX_RANK];
- H5T_str_t str_pad;
- H5T_cset_t cset;
- H5G_stat_t statbuf;
- hid_t super;
- H5T_order_t ord;
- H5T_sign_t sgn;
- size_t sz;
- size_t spos;
- size_t epos;
- size_t esize;
- size_t mpos;
- size_t msize;
- int nmembs;
-
- switch (H5Tget_class(type)) {
- case H5T_INTEGER:
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- /* <IntegerType ByteOrder="bo" Sign="torf" Size="bytes"/> */
- ord = H5Tget_order(type);
- sgn = H5Tget_sign(type);
- indentation(indent);
- printf("<IntegerType ByteOrder=\"");
- switch (ord) {
- case H5T_ORDER_LE:
- printf("LE");
- break;
- case H5T_ORDER_BE:
- printf("BE");
- break;
- case H5T_ORDER_VAX:
- default:
- printf("ERROR_UNKNOWN");
- }
- printf("\" Sign=\"");
- switch (sgn) {
- case H5T_SGN_NONE:
- printf("false");
- break;
- case H5T_SGN_2:
- printf("true");
- break;
- default:
- printf("ERROR_UNKNOWN");
- }
- printf("\" Size=\"");
- sz = H5Tget_size(type);
- printf("%d", sz);
- printf("\" />\n");
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_FLOAT:
- /* <FloatType ByteOrder="bo" Size="bytes"
- SignBitLocation="bytes"
- ExponentBits="eb" ExponentLocation="el"
- MatissaBits="mb" MatissaLocation="ml" /> */
- ord = H5Tget_order(type);
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<FloatType ByteOrder=\"");
- switch (ord) {
- case H5T_ORDER_LE:
- printf("LE");
- break;
- case H5T_ORDER_BE:
- printf("BE");
- break;
- case H5T_ORDER_VAX:
- default:
- printf("ERROR_UNKNOWN");
- }
- printf("\" Size=\"");
- sz = H5Tget_size(type);
- printf("%d", sz);
- H5Tget_fields(type, &spos, &epos, &esize, &mpos, &msize);
- printf("\" SignBitLocation=\"%d\" ", spos);
- printf("ExponentBits=\"%d\" ExponentLocation=\"%d\" ", esize, epos);
- printf("MantissaBits=\"%d\" MantissaLocation=\"%d\" />\n",
- msize, mpos);
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_TIME:
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<TimeType />\n");
- printf("<!-- H5T_TIME: not yet implemented -->");
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_STRING:
- /* <StringType Cset="cs" StrSize="chars" StrPad="pad" /> */
- size = H5Tget_size(type);
- str_pad = H5Tget_strpad(type);
- cset = H5Tget_cset(type);
-
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<StringType Cset=\"");
- if (cset == H5T_CSET_ASCII) {
- printf("H5T_CSET_ASCII\" ");
- } else {
- printf("unknown_cset\" ");
- }
- printf("StrSize=\"%d\" StrPad=\"", (int) size);
- if (str_pad == H5T_STR_NULLTERM) {
- printf("H5T_STR_NULLTERM\"/>\n");
- } else if (str_pad == H5T_STR_NULLPAD) {
- printf("H5T_STR_NULLPAD\"/>\n");
- } else if (str_pad == H5T_STR_SPACEPAD) {
- printf("H5T_STR_SPACEPAD\"/>\n");
- } else {
- printf("H5T_STR_ERROR\"/>\n");
- }
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_BITFIELD:
- /* <BitfieldType ByteOrder="bo" Size="bytes"/> */
- ord = H5Tget_order(type);
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<BitfieldType ByteOrder=\"");
- switch (ord) {
- case H5T_ORDER_LE:
- printf("LE");
- break;
- case H5T_ORDER_BE:
- printf("BE");
- break;
- case H5T_ORDER_VAX:
- default:
- printf("ERROR_UNKNOWN");
- }
- size = H5Tget_size(type);
- printf("\" Size=\"%d\"/>\n", size);
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_OPAQUE:
- /* <OpaqueType Tag="tag" Size="bytes" /> */
-
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<OpaqueType Tag=\"%s\" ", H5Tget_tag(type));
- size = H5Tget_size(type);
- printf("Size=\"%d\"/>\n", size);
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_COMPOUND:
- /* recursively describe the components of a compound datatype */
- if (H5Tcommitted(type) > 0) {
- /* detect a shared datatype, output only once */
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
- i = search_obj(type_table, statbuf.objno);
-
- if (i >= 0) {
- /* This should be defined somewhere else */
- if (!type_table->objs[i].recorded) {
- /* 'anonymous' NDT. Use it's object num.
- as it's name. */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("/#%lu:%lu",
- type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- printf("\"/>\n");
- } else {
- /* point to the NDT by name */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("%s",
- xml_escape_the_name(type_table->objs[i].objname));
- printf("\"/>\n");
- }
- } else {
- printf("<!-- h5dump error: unknown committed type. -->\n");
- d_status = EXIT_FAILURE;
- }
-
- } else {
- /* type of a dataset */
- nmembers = H5Tget_nmembers(type);
-
- indentation(indent);
- printf("<CompoundType>\n");
-
- /* List each member Field of the type */
- /* <Field FieldName="name" > */
- /* <DataType > */
- indent += COL;
- for (i = 0; i < nmembers; i++) {
- fname = H5Tget_member_name(type, i);
- mtype = H5Tget_member_type(type, i);
- indentation(indent);
- printf("<Field FieldName=\"%s\">\n",
- xml_escape_the_name(fname));
-
- free(fname);
- indent += COL;
- indentation(indent);
- printf("<DataType>\n");
- indent += COL;
- xml_print_datatype(mtype);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
-
- indentation(indent);
- printf("</Field>\n");
- }
- indent -= COL;
- indentation(indent);
- printf("</CompoundType>\n");
- }
- break;
-
- case H5T_REFERENCE:
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- /* Only Object references supported at this time */
- printf("<ReferenceType>\n");
- indentation(indent + COL);
- printf("<ObjectReferenceType />\n");
- indentation(indent);
- printf("</ReferenceType>\n");
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_ENUM:
- /* <EnumType Nelems="ne" >
- list Name, values of enum
- */
- nmembs = H5Tget_nmembers(type);
- indentation(indent);
- printf("<AtomicType>\n");
- indent += COL;
- indentation(indent);
- printf("<EnumType Nelems=\"%d\">\n", nmembs);
- xml_print_enum(type);
- indentation(indent);
- printf("</EnumType>\n");
- indent -= COL;
- indentation(indent);
- printf("</AtomicType>\n");
- break;
-
- case H5T_VLEN:
- indentation(indent);
- printf("<VLType>\n");
- super = H5Tget_super(type);
- indent += COL;
- indentation(indent);
- printf("<DataType>\n");
- indent += COL;
- xml_print_datatype(super);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
- indentation(indent);
- printf("</VLType>\n");
- H5Tclose(super);
-
- break;
-
- case H5T_ARRAY:
- /* Get array base type */
- super = H5Tget_super(type);
-
- /* Print lead-in */
- indentation(indent);
- printf("<ArrayType Ndims=\"");
- ndims = H5Tget_array_ndims(type);
- printf("%d\">\n", ndims);
-
- /* Get array information */
- H5Tget_array_dims(type, dims, perm);
-
- /* list of dimensions */
- indent += COL;
- if (perm != NULL) {
- /* for each dimension, list */
- for (j = 0; j < ndims; j++) {
- indentation(indent);
- printf("<ArrayDimension DimSize=\"%u\" DimPerm=\"%u\"/>\n",
- (int) dims[j], (int) perm[j]);
- }
- } else {
- for (j = 0; j < ndims; j++) {
- indentation(indent);
- printf("<ArrayDimension DimSize=\"%u\" DimPerm=\"0\"/>\n",
- (int) dims[j]);
- }
- }
- indent -= COL;
-
- indent += COL;
- indentation(indent);
- printf("<DataType>\n");
- indent += COL;
- xml_print_datatype(super);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
- indentation(indent);
- printf("</ArrayType>\n");
- /* Close array base type */
- H5Tclose(super);
- break;
-
- default:
- printf("<!-- unknown data type -->");
- d_status = EXIT_FAILURE;
- break;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_datatype
- *
- * Purpose: Dump description of a datatype in XML.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_datatype(hid_t type)
-{
- int i;
- H5G_stat_t statbuf;
-
- indent += COL;
- indentation(indent);
-
- if (H5Tcommitted(type) > 0) {
- /* Data type is a shared or named data type */
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
- i = search_obj(type_table, statbuf.objno);
-
- if (i >= 0) {
- /* Shared data type, must be entered as an object */
- if (!type_table->objs[i].recorded) {
- /* anonymous stored data type:
- following the dumper's current
- practice:
- use it's object ref as its name
- */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("/#%lu:%lu",
- type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- printf("\"/>\n");
- } else {
- /* pointer to a named data type already in XML */
- printf("<NamedDataTypePtr OBJ-XID=\"");
- printf("%s",
- xml_escape_the_name(type_table->objs[i].objname));
- printf("\"/>\n");
- }
- } else {
- printf("<!-- h5dump error: unknown committed type. -->\n");
- }
- indent -= COL;
- return;
- }
- printf("%s %s\n", dump_header_format->datatypebegin,
- dump_header_format->datatypeblockbegin);
- indent += COL;
- xml_print_datatype(type);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_dataspace
- *
- * Purpose: Dump description of a dataspace in XML.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_dataspace(hid_t space)
-{
- hsize_t size[H5DUMP_MAX_RANK];
- hsize_t maxsize[H5DUMP_MAX_RANK];
- int ndims =
- H5Sget_simple_extent_dims(space, size, maxsize);
- int i;
-
- indentation(indent + COL);
- printf("%s\n", dump_header_format->dataspacebegin);
- if (H5Sis_simple(space)) {
- indentation(indent + COL + COL);
-
- if (ndims == 0) {
- /* scalar dataspace (just a tag, no XML attrs. defined */
- printf("<ScalarDataspace />\n");
- } else {
- /* simple dataspace */
- /* <SimpleDataspace Ndims="nd"> */
- printf("<SimpleDataspace Ndims=\"%d\">\n", ndims);
-
- /* print the <Dimension> elements */
- for (i = 0; i < ndims; i++) {
- indentation(indent + COL + COL + COL);
- if (maxsize[i] == H5S_UNLIMITED) {
- HDfprintf(stdout,
- "<Dimension DimSize=\"%Hu\" MaxDimSize=\"UNLIMITED\"/>\n",
- size[i]);
- } else if (maxsize[i] == (hsize_t) 0) {
- HDfprintf(stdout,
- "<Dimension DimSize=\"%Hu\" MaxDimSize=\"%Hu\"/>\n",
- size[i], size[i]);
- } else {
- HDfprintf(stdout,
- "<Dimension DimSize=\"%Hu\" MaxDimSize=\"%Hu\"/>\n",
- size[i], maxsize[i]);
- }
- }
- indentation(indent + COL + COL);
- printf("</SimpleDataspace>\n");
- }
- } else {
- printf("<!-- not yet implemented -->\n");
- }
-
- indentation(indent + COL);
- printf("%s\n", dump_header_format->dataspaceend);
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_data
- *
- * Purpose: Dump description of data in XML.
- * Note that this calls the h5dump_xxx calls in
- * the h5tools library.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_data(hid_t obj_id, int obj_data)
-{
- h5dump_t *outputformat = &xml_dataformat;
- int status = -1;
- void *buf;
- hid_t space, type, p_type;
- int ndims, i;
- hsize_t size[64], nelmts = 1;
- int depth;
- int stdindent = COL; /* should be 3 */
-
- outputformat->line_ncols = nCols;
-
- indent += COL;
-
- /*
- * the depth will tell us how far we need to indent extra. we use to just
- * use indent but with the merging of the tools lib we have to do
- * something different for the lib funtions... the normal indentation is 6
- * so when we don't need any extra indentation, depth will be 0.
- */
- depth = indent / stdindent + 1;
-
- /* Print all the values. */
- indentation(indent);
- printf("%s\n", dump_header_format->databegin);
- indentation(indent + COL);
- printf("<DataFromFile>\n");
- if (obj_data == DATASET_DATA) {
- type = H5Dget_type(obj_id);
- if (H5Tget_class(type) == H5T_REFERENCE) {
- status = xml_print_refs(obj_id, DATASET_DATA);
- } else if (H5Tget_class(type) == H5T_STRING) {
- status = xml_print_strs(obj_id, DATASET_DATA);
- } else {
- status = h5dump_dset(stdout, outputformat, obj_id, -1, depth);
- }
- } else {
- /* Attribute data */
- type = H5Aget_type(obj_id);
-
- if (H5Tget_class(type) == H5T_REFERENCE) {
- /* references are done differently than
- the standard output:
- XML dumps a path to the object
- referenced.
- */
- status = xml_print_refs(obj_id, ATTRIBUTE_DATA);
- H5Tclose(type);
- } else if (H5Tget_class(type) == H5T_STRING) {
- status = xml_print_strs(obj_id, ATTRIBUTE_DATA);
- } else {
- /* all other data */
- p_type = h5dump_fixtype(type);
- H5Tclose(type);
-
- space = H5Aget_space(obj_id);
-
- ndims = H5Sget_simple_extent_dims(space, size, NULL);
-
- for (i = 0; i < ndims; i++)
- nelmts *= size[i];
-
- buf =
- malloc((size_t)(nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type))));
- assert(buf);
-
- if (H5Aread(obj_id, p_type, buf) >= 0) {
- status =
- h5dump_mem(stdout, outputformat, obj_id, p_type, space,
- buf, depth);
- }
- free(buf);
- H5Tclose(p_type);
- H5Sclose(space);
- H5Tclose(type);
- }
- }
-
- if (status < 0) {
- indentation(indent + COL);
- printf("Unable to print data.\n");
- status = 1;
- }
-
- indentation(indent + COL);
- printf("</DataFromFile>\n");
- indentation(indent);
- printf("%s\n", dump_header_format->dataend);
- indent -= COL;
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_attr
- *
- * Purpose: Dump a description of an HDF5 attribute in XML.
- *
- * Return: herr_t
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-xml_dump_attr(hid_t attr, const char *attr_name, void UNUSED * op_data)
-{
- hid_t attr_id, type, space;
-
- indentation(indent);
- printf("<Attribute Name=\"%s\">\n", xml_escape_the_name(attr_name));
-
- if ((attr_id = H5Aopen_name(attr, attr_name)) >= 0) {
- type = H5Aget_type(attr_id);
- space = H5Aget_space(attr_id);
-
- dump_function_table->dump_dataspace_function(space);
- dump_function_table->dump_datatype_function(type);
-
- if (display_data) {
- switch (H5Tget_class(type)) {
- case H5T_INTEGER:
- case H5T_FLOAT:
- case H5T_STRING:
- case H5T_BITFIELD:
- case H5T_OPAQUE:
- case H5T_ENUM:
- case H5T_ARRAY:
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
- break;
-
- case H5T_TIME:
- indent += COL;
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<!-- Time data not yet implemented. -->\n");
- indentation(indent);
- printf("<NoData />\n");
- indentation(indent);
- printf("<Data>\n");
- indent -= COL;
- break;
-
- case H5T_COMPOUND:
- indentation(indent);
- printf
- ("<!-- Note: format of compound data not specified -->\n");
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
- break;
-
- case H5T_REFERENCE:
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<DataFromFile>\n");
- xml_print_refs(attr_id, ATTRIBUTE_DATA);
- indentation(indent);
- printf("</DataFromFile>\n");
- indentation(indent);
- printf("</Data>\n");
- break;
-
- case H5T_VLEN:
- printf("<!-- Note: format of VL data not specified -->\n");
- dump_function_table->dump_data_function(attr_id,
- ATTRIBUTE_DATA);
- break;
- default:
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<!-- Unknown datatype: %d -->\n", H5Tget_class(type));
- indentation(indent);
- printf("<NoData/>\n");
- indentation(indent);
- printf("</Data>\n");
- break;
- }
- } else {
- /* The case of an attribute never yet written ?? */
- indentation(indent);
- printf("<Data>\n");
- indentation(indent + COL);
- printf("<NoData/>\n");
- indentation(indent);
- printf("</Data>\n");
- }
-
- H5Tclose(type);
- H5Sclose(space);
- H5Aclose(attr_id);
- indentation(indent);
- printf("%s\n", dump_header_format->attributeend);
- return SUCCEED;
-
- } else {
- /* ?? failed */
- indentation(indent + COL);
- printf("<!-- h5dump error: unable to open attribute. -->\n");
- indentation(indent);
- printf("%s\n", dump_header_format->attributeend);
- d_status = EXIT_FAILURE;
- return FAIL;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_named_datatype
- *
- * Purpose: Dump a description of an HDF5 NDT in XML.
- *
- * Return: herr_t
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_named_datatype(hid_t type, const char *name)
-{
- int nmembers = 1, x;
- hid_t mtype;
- char *fname;
- char *tmp;
-
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
- strcpy(tmp, prefix);
- strcat(tmp, "/");
- strcat(tmp, name);
-
- indentation(indent);
- if (strncmp(name, "#", 1) == 0) {
- /* Special: this is an 'anonymous' NDT, deleted but
- still in use.
- We follow the dumper's undocumented practice, and
- use its object id as its name.
- Exactly the same as normal, but a separate case
- in the event we want to do something else in
- the future.
- */
- printf("<NamedDataType Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- name,
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
- } else {
- printf("<NamedDataType Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
- }
-
- indent += COL;
- if (H5Tget_class(type) == H5T_COMPOUND) {
- /* Dump this here for sure. */
- nmembers = H5Tget_nmembers(type);
-
- indentation(indent);
- printf("<CompoundType>\n");
-
- indent += COL;
- for (x = 0; x < nmembers; x++) {
- fname = H5Tget_member_name(type, x);
- mtype = H5Tget_member_type(type, x);
- indentation(indent);
- printf("<Field FieldName=\"%s\">\n", xml_escape_the_name(fname));
- free(fname);
-
- if ((H5Tget_class(mtype) == H5T_COMPOUND)
- || (H5Tget_class(mtype) == H5T_VLEN)
- || (H5Tget_class(mtype) == H5T_ARRAY)) {
- indent += COL;
-
- /* Nested compound type: recur */
- indentation(indent);
- printf("%s %s\n", dump_header_format->datatypebegin,
- dump_header_format->datatypeblockbegin);
- indent += COL;
- xml_print_datatype(mtype);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
- } else {
- indent += COL;
- indentation(indent);
- printf("%s %s\n", dump_header_format->datatypebegin,
- dump_header_format->datatypeblockbegin);
- indent += COL;
- xml_print_datatype(mtype);
- indent -= COL;
- indentation(indent);
- printf("%s\n", dump_header_format->datatypeend);
- indent -= COL;
- }
-
- indentation(indent);
- printf("</Field>\n");
- }
-
- indent -= COL;
- indentation(indent);
- printf("</CompoundType>\n");
- } else {
- /* Other data types: call print_datatype */
- indent += COL;
- xml_print_datatype(type);
- indent -= COL;
- }
-
- indent -= COL;
- indentation(indent);
- printf("</NamedDataType>\n");
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_group
- *
- * Purpose: Dump a description of an HDF5 Group (and its members) in XML.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_group(hid_t gid, const char *name)
-{
- H5G_stat_t statbuf;
- char *cp;
- hid_t dset, type;
- char typename[1024], *tmp;
- char *par;
- int i;
- int isRoot = 0;
- int xtype;
-
- if (strcmp(name, "/") == 0) {
- isRoot = 1;
- } else {
- tmp = malloc(strlen(prefix) + strlen(name) + 2);
- strcpy(tmp, prefix);
- par = strdup(tmp);
- cp = strrchr(par, '/');
- if (cp != NULL) {
- if ((cp == par) && strlen(par) > 1) {
- *(cp + 1) = '\0';
- } else {
- *cp = '\0';
- }
- }
- }
- indentation(indent);
- if (isRoot) {
- printf("<RootGroup OBJ-XID=\"root\">\n");
- } else {
- printf("<Group Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\" >\n",
- xml_escape_the_name(name),
- xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(par) : "root"));
- }
- indent += COL;
- H5Gget_objinfo(gid, ".", TRUE, &statbuf);
-
- if (statbuf.nlink > 1) {
- /* Group with more than one link to it... */
- i = search_obj(group_table, statbuf.objno);
-
- if (i < 0) {
- indentation(indent);
- fprintf(stderr, "h5dump error: internal error (line %d)\n", __LINE__);
- d_status = EXIT_FAILURE;
- } else if (group_table->objs[i].displayed) {
- /* already seen: enter a groupptr */
- indentation(indent + COL);
- printf("<GroupPtr OBJ-XID=\"%s\"/>\n",
- xml_escape_the_name(group_table->objs[i].objname));
- } else {
- /* first time this group has been seen -- describe it */
- strcpy(group_table->objs[i].objname, prefix);
- group_table->objs[i].displayed = 1;
-
- /* 1. do all the attributes of the group */
- H5Aiterate(gid, NULL,
- dump_function_table->dump_attribute_function, NULL);
-
- if (!strcmp(name, "/") && unamedtype) {
- /* Very special case: dump unamed type in root group */
- for (i = 0; i < type_table->nobjs; i++) {
- if (!type_table->objs[i].recorded) {
- dset = H5Dopen(gid, type_table->objs[i].objname);
- type = H5Dget_type(dset);
- sprintf(typename, "#%lu:%lu",
- type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- dump_function_table->dump_named_datatype_function
- (type, typename);
- H5Tclose(type);
- H5Dclose(dset);
- }
- }
- }
-
- /* iterate through all the members */
- xtype = H5G_TYPE;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_DATASET;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_LINK;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_GROUP;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- }
- } else {
- /* 1. do all the attributes of the group */
- H5Aiterate(gid, NULL, dump_function_table->dump_attribute_function,
- NULL);
-
- if (!strcmp(name, "/") && unamedtype) {
- /* Very special case: dump unamed type in root group */
- for (i = 0; i < type_table->nobjs; i++) {
- if (!type_table->objs[i].recorded) {
- dset = H5Dopen(gid, type_table->objs[i].objname);
- type = H5Dget_type(dset);
- sprintf(typename, "#%lu:%lu",
- type_table->objs[i].objno[0],
- type_table->objs[i].objno[1]);
- dump_function_table->dump_named_datatype_function(type,
- typename);
- H5Tclose(type);
- H5Dclose(dset);
- }
- }
- }
-
- /* iterate through all the members */
- xtype = H5G_TYPE;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_DATASET;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_LINK;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- xtype = H5G_GROUP;
- H5Giterate(gid, ".", NULL, dump_all, (void *) &xtype);
- }
-
- indent -= COL;
- indentation(indent);
- if (isRoot) {
- printf("</RootGroup>\n");
- } else {
- printf("%s\n", dump_header_format->groupend);
- }
-/* don't free this!!!
- free(tmp);
-*/
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_print_refs
- *
- * Purpose: Print a path to the objects referenced by HDF5 Referneces.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-xml_print_refs(hid_t did, int source)
-{
- herr_t e;
- hid_t type, space;
- char *buf;
- hobj_ref_t *refbuf;
- char *path;
- hsize_t ssiz;
- hsize_t i;
-
- if (source == DATASET_DATA) {
- type = H5Dget_type(did);
- } else if (source == ATTRIBUTE_DATA) {
- type = H5Aget_type(did);
- } else {
- /* return an error */
- return FAIL;
- }
- if (H5Tget_class(type) != H5T_REFERENCE) {
- /* return an error */
- return FAIL;
- }
- if (!H5Tequal(type, H5T_STD_REF_OBJ)) {
- /* region ref not supported yet... */
- /* return an error */
- return FAIL;
- }
- if (source == DATASET_DATA) {
- space = H5Dget_space(did);
- ssiz = H5Sget_simple_extent_npoints(space);
- ssiz *= H5Tget_size(type);
-
- buf = calloc((size_t)ssiz, sizeof(char));
- if (buf == NULL) {
- return FAIL;
- }
- e = H5Dread(did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
- /* need to check result here */
- if (e < 0) {
- free(buf);
- return FAIL;
- }
-
- } else if (source == ATTRIBUTE_DATA) {
- space = H5Aget_space(did);
- ssiz = H5Sget_simple_extent_npoints(space);
- ssiz *= H5Tget_size(type);
-
- buf = calloc((size_t)ssiz, sizeof(char));
- if (buf == NULL) {
- free(buf);
- return FAIL;
- }
- e = H5Aread(did, H5T_STD_REF_OBJ, buf);
- /* need to check the result here */
- } else {
- /* error */
- return FAIL;
- }
-
- refbuf = (hobj_ref_t *) buf;
- ssiz = H5Sget_simple_extent_npoints(space);
-
- for (i = 0; i < ssiz; i++) {
- path = lookup_ref_path(refbuf);
- indentation(indent + COL);
- if (path == NULL) {
- printf("\"%s\"\n", "NULL");
- } else {
- printf("\"%s\"\n", xml_escape_the_string(path, -1));
- }
- refbuf++;
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_print_strs
- *
- * Purpose: Print strings.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-xml_print_strs(hid_t did, int source)
-{
- herr_t e;
- hid_t type, space;
- char *buf;
- char *bp;
- char *onestring;
- hsize_t ssiz;
- size_t tsiz;
- size_t i;
- if (source == DATASET_DATA) {
- type = H5Dget_type(did);
- } else if (source == ATTRIBUTE_DATA) {
- type = H5Aget_type(did);
- } else {
- /* return an error */
- return FAIL;
- }
- if (H5Tget_class(type) != H5T_STRING) {
- /* return an error */
- return FAIL;
- }
- if (source == DATASET_DATA) {
- space = H5Dget_space(did);
- ssiz = H5Sget_simple_extent_npoints(space);
- ssiz *= H5Tget_size(type);
-
- buf = calloc((size_t)ssiz, sizeof(char));
- if (buf == NULL) {
- return FAIL;
- }
- e = H5Dread(did, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
- if (e < 0) {
- free(buf);
- return FAIL;
- }
-
- } else if (source == ATTRIBUTE_DATA) {
- space = H5Aget_space(did);
- ssiz = H5Sget_simple_extent_npoints(space);
- ssiz *= H5Tget_size(type);
-
- buf = calloc((size_t)ssiz, sizeof(char));
- if (buf == NULL) {
- return FAIL;
- }
- e = H5Aread(did, type, buf);
- if (e < 0) {
- free(buf);
- return FAIL;
- }
- } else {
- /* error */
- return FAIL;
- }
-
-/* pull out each string... */
- ssiz = H5Sget_simple_extent_npoints(space);
-
- tsiz = H5Tget_size(type);
- onestring = (char *) calloc((size_t)tsiz, sizeof(char));
- bp = buf;
-
- for (i = 0; i < ssiz; i++) {
- strncpy(onestring, bp, tsiz);
- indentation(indent + COL);
- if (onestring == NULL) {
- printf("\"%s\"\n", "NULL");
- } else {
- printf("\"%s\"\n", xml_escape_the_string(onestring, (int)tsiz));
- }
- bp += tsiz;
- }
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: check_compression
- *
- * Purpose: private function to check for compression and
- * put a comment in the XML. (Not fully implemented.)
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-check_compression(hid_t dcpl)
-{
- int nfilt;
- int i;
- H5Z_filter_t filter;
- char namebuf[20];
- size_t cd_nelmts = 1;
- unsigned int cd_values;
- unsigned int flags;
-/* not used yet: will need to do somehting more elaborate to handle future
- * compression methods.
- char *t1 = "H5Z_FILTER_DEFLATE";
-*/
-
- nfilt = H5Pget_nfilters(dcpl);
- if (nfilt <= 0)
- return;
- for (i = 0; i < nfilt; i++) {
- filter = H5Pget_filter(dcpl, i, &flags,
- (size_t *) &cd_nelmts,
- &cd_values, 20, namebuf);
- if (filter == H5Z_FILTER_DEFLATE) {
- indentation(indent + COL);
- printf("<Compression />\n");
- indentation(indent + COL);
- printf("<!-- Compression parameter %d -->\n", cd_values);
- }
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_dump_group
- *
- * Purpose: Dump a description of an HDF5 Group (and its members) in XML.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_dump_dataset(hid_t did, const char *name)
-{
- hid_t type, space;
- hid_t dcpl;
- int maxdims;
- hsize_t *chsize;
- int ndims;
- int i;
- char *tmp;
-
- tmp = (char *) malloc(strlen(prefix) + strlen(name) + 2);
- strcpy(tmp, prefix);
- strcat(tmp, "/");
- strcat(tmp, name);
- indentation(indent);
- printf("<Dataset Name=\"%s\" OBJ-XID=\"%s\" Parents=\"%s\">\n",
- xml_escape_the_name(name), xml_escape_the_name(tmp),
- (strcmp(prefix, "") ? xml_escape_the_name(prefix) : "root"));
-
- dcpl = H5Dget_create_plist(did);
- type = H5Dget_type(did);
- space = H5Dget_space(did);
-
- /* Print information about chunked storage */
- if (H5D_CHUNKED == H5Pget_layout(dcpl)) {
- maxdims = H5Sget_simple_extent_ndims(space);
- chsize = (hsize_t *) malloc(maxdims * sizeof(hsize_t));
- indent += COL;
- indentation(indent);
- printf("<StorageLayout>\n");
- indent += COL;
- indentation(indent);
- printf("<ChunkedLayout ");
- ndims = H5Pget_chunk(dcpl, maxdims, chsize);
- printf("Ndims=\"%d\">\n", ndims);
- /* check for compression and tell about it... */
-
- check_compression(dcpl);
-
- indent += COL;
- for (i = 0; i < ndims; i++) {
- indentation(indent);
- HDfprintf(stdout,"<ChunkDimension DimSize=\"%Hu\" />\n", chsize[i]);
- }
- indent -= COL;
-
- indentation(indent);
- printf("</ChunkedLayout>\n");
- indent -= COL;
- indentation(indent);
- printf("</StorageLayout>\n");
- indent -= COL;
- free(chsize);
- }
- /* and check for external.... */
-
- dump_function_table->dump_dataspace_function(space);
- dump_function_table->dump_datatype_function(type);
-
- indent += COL;
- H5Aiterate(did, NULL, dump_function_table->dump_attribute_function, NULL);
- indent -= COL;
- i = H5Dget_storage_size(did);
- if (display_data && (i > 0)) {
- switch (H5Tget_class(type)) {
- case H5T_INTEGER:
- case H5T_FLOAT:
- case H5T_STRING:
- case H5T_BITFIELD:
- case H5T_OPAQUE:
- case H5T_ENUM:
- case H5T_ARRAY:
- dump_function_table->dump_data_function(did, DATASET_DATA);
- break;
-
- case H5T_TIME:
- indent += COL;
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<!-- Time data not yet implemented. -->\n");
- indentation(indent);
- printf("<NoData />\n");
- indentation(indent);
- printf("<Data>\n");
- indent -= COL;
- break;
-
- case H5T_COMPOUND:
- indentation(indent);
- printf("<!-- Note: format of compound data not specified -->\n");
- dump_function_table->dump_data_function(did, DATASET_DATA);
- break;
-
- case H5T_REFERENCE:
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<DataFromFile>\n");
- xml_print_refs(did, DATASET_DATA);
- indentation(indent);
- printf("</DataFromFile>\n");
- indentation(indent);
- printf("</Data>\n");
- break;
-
- case H5T_VLEN:
- printf("<!-- Note: format of VL data not specified -->\n");
- dump_function_table->dump_data_function(did, DATASET_DATA);
- break;
- default:
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<!-- Unknown datatype: %d -->\n", H5Tget_class(type));
- indentation(indent);
- printf("<NoData/>\n");
- indentation(indent);
- printf("</Data>\n");
- break;
- }
- } else {
- /* no data written */
- indentation(indent);
- printf("<Data>\n");
- indentation(indent);
- printf("<NoData/>\n");
- indentation(indent);
- printf("</Data>\n");
- }
-
-/*
- free(tmp);
-*/
- H5Tclose(type);
- H5Sclose(space);
- indentation(indent);
- printf("%s\n", dump_header_format->datasetend);
-}
-
-/*-------------------------------------------------------------------------
- * Function: xml_print_enum
- *
- * Purpose: Print the values of an HDF5 ENUM in XML.
- * Very similar to regular DDL output.
- *
- * Return: void
- *
- * Programmer: REMcG
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-xml_print_enum(hid_t type)
-{
- char **name = NULL; /*member names */
- unsigned char *value = NULL; /*value array */
- int nmembs; /*number of members */
- hid_t super; /*enum base integer type */
- hid_t native = -1; /*native integer data type */
- size_t dst_size; /*destination value type size */
- int i; /*miscellaneous counters */
- size_t j;
-
- nmembs = H5Tget_nmembers(type);
- super = H5Tget_super(type);
-
- /*
- * Determine what data type to use for the native values. To simplify
- * things we entertain three possibilities:
- * 1. long_long -- the largest native signed integer
- * 2. unsigned long_long -- the largest native unsigned integer
- * 3. raw format
- */
- if (H5Tget_size(type) <= sizeof(long_long)) {
- dst_size = sizeof(long_long);
-
- if (H5T_SGN_NONE == H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
- }
- } else {
- dst_size = H5Tget_size(type);
- }
-
- /* Get the names and raw values of all members */
- name = calloc((size_t)nmembs, sizeof(char *));
- value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
-
- for (i = 0; i < nmembs; i++) {
- name[i] = H5Tget_member_name(type, i);
- H5Tget_member_value(type, i, value + i * H5Tget_size(type));
- }
-
- /* Convert values to native data type */
- if (native > 0)
- H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
-
- /* Sort members by increasing value */
- /*not implemented yet */
-
- /* Print members */
- indent += COL;
- for (i = 0; i < nmembs; i++) {
- indentation(indent);
- printf("<EnumElement>\n");
- indentation(indent + COL);
- printf("%s\n", xml_escape_the_name(name[i]));
- indentation(indent);
- printf("</EnumElement>\n");
- indentation(indent);
- printf("<EnumValue>\n");
- indentation(indent + COL);
- if (native < 0) {
- printf("0x");
-
- for (j = 0; j < dst_size; j++)
- printf("%02x", value[i * dst_size + j]);
- } else if (H5T_SGN_NONE == H5Tget_sign(native)) {
- printf("%" PRINTF_LL_WIDTH "u", *((unsigned long_long *)
- ((void *) (value + i * dst_size))));
- } else {
- printf("%" PRINTF_LL_WIDTH "d",
- *((long_long *) ((void *) (value + i * dst_size))));
- }
- printf("\n");
- indentation(indent);
- printf("</EnumValue>\n");
-
- }
- indent -= COL;
-
- /* Release resources */
- for (i = 0; i < nmembs; i++)
- free(name[i]);
-
- free(name);
- free(value);
- H5Tclose(super);
-}
diff --git a/tools/h5dump.h b/tools/h5dump.h
deleted file mode 100644
index 6e4c54f..0000000
--- a/tools/h5dump.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef H5DUMP_H__
-#define H5DUMP_H__
-
-#include <hdf5.h>
-
-#define H5DUMP_MAX_RANK H5S_MAX_RANK
-
-#define begin_obj(obj,name,begin) \
- if (name) \
- printf("%s \"%s\" %s\n", (obj), (name), (begin)); \
- else \
- printf("%s %s\n", (obj), (begin));
-
-#define end_obj(obj,end) \
- printf("%s %s\n", (end), (obj));
-
-#endif /* H5DUMP_H__ */
diff --git a/tools/h5dumptst.c b/tools/h5dumptst.c
deleted file mode 100644
index 4e01627..0000000
--- a/tools/h5dumptst.c
+++ /dev/null
@@ -1,2577 +0,0 @@
-/*
- * Generate the binary hdf5 files for the h5dump tests.
- * Usage: just execute the program without any arguments will
- * generate all the binary hdf5 files in the local directory.
- *
- * If you regenerate the test files (e.g., changing some code,
- * trying it on a new platform, ...), you need to verify the correctness
- * of the expected output and update the corresponding *.ddl files.
- */
-#include <limits.h>
-#include "hdf5.h"
-#include <H5private.h>
-
-#define FILE1 "tgroup.h5"
-#define FILE2 "tdset.h5"
-#define FILE3 "tattr.h5"
-#define FILE4 "tslink.h5"
-#define FILE5 "thlink.h5"
-#define FILE6 "tcompound.h5"
-#define FILE7 "tall.h5"
-#define FILE8 "tdset2.h5"
-#define FILE9 "tcompound2.h5"
-#define FILE10 "tloop.h5"
-#define FILE11 "tloop2.h5"
-#define FILE12 "tmany.h5"
-#define FILE13 "tstr.h5"
-#define FILE14 "tstr2.h5"
-#define FILE15 "tenum.h5"
-#define FILE16 "tobjref.h5"
-#define FILE17 "tdatareg.h5"
-#define FILE18 "tnestedcomp.h5"
-#define FILE19 "topaque.h5"
-#define FILE20 "tbitfields.h5"
-#define FILE21 "tvldtypes1.h5"
-#define FILE22 "tvldtypes2.h5"
-#define FILE23 "tvldtypes3.h5"
-#define FILE24 "tvldtypes4.h5"
-#define FILE25 "tarray1.h5"
-#define FILE26 "tarray2.h5"
-#define FILE27 "tarray3.h5"
-#define FILE28 "tarray4.h5"
-#define FILE29 "tarray5.h5"
-#define FILE30 "tarray6.h5"
-#define FILE31 "tarray7.h5"
-#define FILE32 "tempty.h5"
-
-#define LENSTR 50
-#define LENSTR2 11
-
-#define SPACE2_RANK 2
-#define SPACE2_DIM1 10
-#define SPACE2_DIM2 10
-
-#define SPACE1_RANK 1
-#define SPACE1_DIM1 4
-
-/* Element selection information */
-#define POINT1_NPOINTS 10
-
-typedef enum{
- RED,
- GREEN,
- BLUE,
- WHITE,
- BLACK
-} enumtype;
-
-/* Compound datatype */
-typedef struct s1_t {
- unsigned int a;
- unsigned int b;
- float c;
-} s1_t;
-
-
-/* 1-D array datatype */
-#define ARRAY1_RANK 1
-#define ARRAY1_DIM1 4
-
-/* 3-D array datatype */
-#define ARRAY2_RANK 3
-#define ARRAY2_DIM1 3
-#define ARRAY2_DIM2 4
-#define ARRAY2_DIM3 5
-
-/* 2-D array datatype */
-#define ARRAY3_RANK 2
-#define ARRAY3_DIM1 6
-#define ARRAY3_DIM2 3
-
-static void test_group(void)
-{
- hid_t fid, group;
-
- fid = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* / */
- group = H5Gcreate (fid, "/g1", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g2", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g3", 0);
- H5Gclose(group);
-
- /* /g1 */
- group = H5Gcreate (fid, "/g1/g1.1", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g1/g1.2", 0);
- H5Gclose(group);
-
- /* /g2 */
- group = H5Gcreate (fid, "/g2/g2.1", 0);
- H5Gclose(group);
-
- /* /g3 */
- group = H5Gcreate (fid, "/g3/g3.1", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g3/g3.2", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g3/g3.3", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g3/g3.4", 0);
- H5Gclose(group);
-
- /* /g2/g2.1 */
- group = H5Gcreate (fid, "/g2/g2.1/g2.1.1", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g2/g2.1/g2.1.2", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g2/g2.1/g2.1.3", 0);
- H5Gclose(group);
-
- H5Fclose(fid);
-}
-
-static void test_dataset(void)
-{
- hid_t fid, dataset, space;
- hsize_t dims[2];
- int dset1[10][20];
- double dset2[30][20];
- int i, j;
-
- fid = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* dset1 */
- dims[0] = 10; dims[1] = 20;
- space = H5Screate_simple(2, dims, NULL);
- dataset = H5Dcreate(fid, "/dset1", H5T_STD_I32BE, space, H5P_DEFAULT);
-
- for (i = 0; i < 10; i++)
- for (j = 0; j < 20; j++)
- dset1[i][j] = j+i;
-
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* dset2 */
- dims[0] = 30; dims[1] = 20;
- space = H5Screate_simple(2, dims, NULL);
- dataset = H5Dcreate(fid, "/dset2", H5T_IEEE_F64BE, space, H5P_DEFAULT);
-
- for (i = 0; i < 30; i++)
- for (j = 0; j < 20; j++)
- dset2[i][j] = 0.0001*j+i;
-
- H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
-
- H5Sclose(space);
- H5Dclose(dataset);
- H5Fclose(fid);
-}
-
-static void test_dataset2(void)
-{
- hid_t fid, dataset, space, create_plist;
- hsize_t dims[2];
- hsize_t maxdims[2];
- int dset1[10][20];
- double dset2[30][10];
- int i, j;
-
- fid = H5Fcreate(FILE8, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
- dims[0] = 5; dims[1] = 5;
- H5Pset_chunk(create_plist, 2, dims);
-
- /* dset1 */
- dims[0] = 10; dims[1] = 20;
- maxdims[0] = H5S_UNLIMITED; maxdims[1] = 20;
- space = H5Screate_simple(2, dims, maxdims);
- dataset = H5Dcreate(fid, "/dset1", H5T_STD_I32BE, space, create_plist);
-
- for (i = 0; i < 10; i++)
- for (j = 0; j < 20; j++)
- dset1[i][j] = j;
-
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* dset2 */
- dims[0] = 30; dims[1] = 10;
- maxdims[0] = 30; maxdims[1] = H5S_UNLIMITED;
- space = H5Screate_simple(2, dims, maxdims);
- dataset = H5Dcreate(fid, "/dset2", H5T_IEEE_F64BE, space, create_plist);
-
- for (i = 0; i < 30; i++)
- for (j = 0; j < 10; j++)
- dset2[i][j] = j;
-
- H5Dwrite(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
-
- H5Sclose(space);
- H5Dclose(dataset);
- H5Fclose(fid);
-}
-
-
-static void test_attribute(void)
-{
- hid_t fid, root, space, attr, type;
- hsize_t dims[2];
- char buf[60];
- int i, data[10];
- double d[10];
- char string[]= "string attribute";
- int point = 100;
-
- fid = H5Fcreate(FILE3, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- root = H5Gopen (fid, "/");
-
- /* attribute 1 */
- dims[0] = 24;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (root, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT);
- sprintf(buf, "attribute of root group");
- H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
- H5Sclose(space);
- H5Aclose(attr);
-
- /* attribute 2 */
- dims[0] = 10;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (root, "attr2", H5T_STD_I32BE, space, H5P_DEFAULT);
-
- for (i = 0; i < 10; i++) data[i] = i+1;
-
- H5Awrite(attr, H5T_NATIVE_INT, data);
- H5Sclose(space);
- H5Aclose(attr);
-
- /* attribute 3 */
- dims[0] = 10;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (root, "attr3", H5T_IEEE_F64BE, space, H5P_DEFAULT);
-
- for (i = 0; i < 10; i++) d[i] = 0.1 * i;
-
- H5Awrite(attr, H5T_NATIVE_DOUBLE, d);
- H5Sclose(space);
- H5Aclose(attr);
-
- /* attribute 4 */
- space = H5Screate(H5S_SCALAR);
- attr = H5Acreate (root, "attr4", H5T_STD_I32BE, space, H5P_DEFAULT);
- H5Awrite(attr, H5T_NATIVE_INT, &point);
- H5Sclose(space);
- H5Aclose(attr);
-
- /* attribute 5 */
- space = H5Screate(H5S_SCALAR);
- type = H5Tcopy(H5T_C_S1);
- H5Tset_size(type, 17);
- attr = H5Acreate (root, "attr5", type, space, H5P_DEFAULT);
- H5Awrite(attr, type, string);
-
- H5Tclose(type);
- H5Sclose(space);
- H5Aclose(attr);
- H5Gclose(root);
- H5Fclose(fid);
-}
-
-static void test_softlink(void)
-{
- hid_t fid, root;
-
- fid = H5Fcreate(FILE4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- root = H5Gopen (fid, "/");
- H5Glink (root, H5G_LINK_SOFT, "somevalue", "slink1");
- H5Glink (root, H5G_LINK_SOFT, "linkvalue", "slink2");
-
- H5Gclose(root);
- H5Fclose(fid);
-}
-
-/*
- /
-
- / | \ the dataset is hardlinked to three names
- /dset1, /g1/dset2, and /g1/g1.1/dset3
- dset1 g1 g2
- /g2 and /g1/g1.1 are hardlinked to the same object.
- / \
- dset2 g1.1
- |
- dset3
-*/
-
-static void test_hardlink(void)
-{
- hid_t fid, group, dataset, space;
- hsize_t dim = 5;
- int i, dset[5];
-
- fid = H5Fcreate(FILE5, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- space = H5Screate_simple(1, &dim, NULL);
- dataset = H5Dcreate(fid, "/dset1", H5T_STD_I32BE, space, H5P_DEFAULT);
-
- for (i = 0; i < 5; i++) dset[i] = i;
-
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset);
- H5Sclose(space);
- H5Dclose(dataset);
-
- group = H5Gcreate (fid, "/g1", 0);
- H5Glink (group, H5G_LINK_HARD, "/dset1", "dset2");
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g2", 0);
- H5Glink (group, H5G_LINK_HARD, "/dset1", "dset3");
- H5Gclose(group);
-
- group = H5Gopen(fid, "/g1");
- H5Glink (group, H5G_LINK_HARD, "/g2", "g1.1");
- H5Gclose(group);
- H5Fclose(fid);
-}
-
-/*
- /
- / | \ \
- dset1 group1 type1 type2
- |
- dset2
-
-*/
-static void test_compound_dt(void) { /* test compound data type */
- hid_t fid, group, dataset, space, space3, type, type2;
- hid_t array_dt;
- typedef struct {
- int a;
- float b;
- double c;
- } dset1_t;
- dset1_t dset1[5];
-
- typedef struct {
- int a;
- float b;
- } dset2_t;
- dset2_t dset2[5];
-
- typedef struct {
- int a[4];
- float b[5][6];
- } dset3_t;
- dset3_t dset3[3][6];
-
- typedef struct {
- int a;
- float b;
- } dset4_t;
- dset4_t dset4[5];
-
- typedef struct {
- int a;
- float b;
- } dset5_t;
- dset5_t dset5[5];
-
- int i, j, k, l, ndims;
- hsize_t dim[2];
-
- hsize_t sdim = 5;
- hsize_t dset3_dim[2];
-
-
- for (i = 0; i < (int)sdim; i++) {
- dset1[i].a = i;
- dset1[i].b = i*i;
- dset1[i].c = 1./(i+1);
-
- dset2[i].a = i;
- dset2[i].b = i+ i*0.1;
-
- dset4[i].a = i;
- dset4[i].b = i+3;
-
- dset5[i].a = i;
- dset5[i].b = i*0.1;
- }
-
-
- fid = H5Fcreate(FILE6, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- space = H5Screate_simple(1, &sdim, NULL);
-
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset1[0]));
- type2 = H5Tcreate(H5T_COMPOUND, sizeof(dset1[0]));
- H5Tinsert(type, "a_name", HOFFSET(dset1_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "b_name", HOFFSET(dset1_t, b), H5T_IEEE_F32BE);
- H5Tinsert(type, "c_name", HOFFSET(dset1_t, c), H5T_IEEE_F64BE);
- H5Tinsert(type2, "a_name", HOFFSET(dset1_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "b_name", HOFFSET(dset1_t, b), H5T_NATIVE_FLOAT);
- H5Tinsert(type2, "c_name", HOFFSET(dset1_t, c), H5T_NATIVE_DOUBLE);
- dataset = H5Dcreate(fid, "/dset1", type, space, H5P_DEFAULT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
- H5Tclose(type2);
- H5Tclose(type);
- H5Dclose(dataset);
-
- /* shared data type 1 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset2_t));
- H5Tinsert(type, "int_name", HOFFSET(dset2_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float_name", HOFFSET(dset2_t, b), H5T_IEEE_F32BE);
- H5Tcommit(fid, "type1", type);
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset2_t));
- H5Tinsert(type2, "int_name", HOFFSET(dset2_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float_name", HOFFSET(dset2_t, b), H5T_NATIVE_FLOAT);
- group = H5Gcreate (fid, "/group1", 0);
-
- dataset = H5Dcreate(group, "dset2", type, space, H5P_DEFAULT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
- H5Tclose(type2);
- H5Tclose(type);
- H5Dclose(dataset);
-
-
- /* shared data type 2 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset3_t));
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset3_t));
-
- ndims = 1; dim[0] = 4;
-
- array_dt=H5Tarray_create(H5T_STD_I32BE,ndims,dim,NULL);
- H5Tinsert(type, "int_array", HOFFSET(dset3_t, a), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_NATIVE_INT,ndims,dim,NULL);
- H5Tinsert(type2, "int_array", HOFFSET(dset3_t, a), array_dt);
- H5Tclose(array_dt);
-
- ndims = 2; dim[0] = 5; dim[1] = 6;
-
- array_dt=H5Tarray_create(H5T_IEEE_F32BE,ndims,dim,NULL);
- H5Tinsert(type, "float_array", HOFFSET(dset3_t, b), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,ndims,dim,NULL);
- H5Tinsert(type2, "float_array", HOFFSET(dset3_t, b), array_dt);
- H5Tclose(array_dt);
-
- H5Tcommit(fid, "type2", type);
-
-
- dset3_dim[0] = 3; dset3_dim[1] = 6;
- space3 = H5Screate_simple(2, dset3_dim, NULL);
- dataset = H5Dcreate(group, "dset3", type, space3, H5P_DEFAULT);
- for (i = 0; i < (int)dset3_dim[0]; i++) {
- for (j = 0; j < (int)dset3_dim[1]; j++) {
- for (k = 0; k < 4; k++)
- dset3[i][j].a[k] = k+j+i;
- for (k = 0; k < 5; k++)
- for (l = 0; l < 6; l++)
- dset3[i][j].b[k][l] = (k+1)+l+j+i;
- }
- }
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset3);
- H5Sclose(space3);
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
-
- /* shared data type 3 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset4_t));
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset4_t));
- H5Tinsert(type, "int", HOFFSET(dset4_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float", HOFFSET(dset4_t, b), H5T_IEEE_F32BE);
- H5Tcommit(group, "type3", type);
- H5Tinsert(type2, "int", HOFFSET(dset4_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float", HOFFSET(dset4_t, b), H5T_NATIVE_FLOAT);
- dataset = H5Dcreate(group, "dset4", type, space, H5P_DEFAULT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset4);
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
- H5Gclose(group);
-
-
- /* unamed data type */
- group = H5Gcreate (fid, "/group2", 0);
-
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset5_t));
- H5Tinsert(type, "int", HOFFSET(dset5_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float", HOFFSET(dset5_t, b), H5T_IEEE_F32BE);
- H5Tcommit(group, "type4", type);
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset5_t));
- H5Tinsert(type2, "int", HOFFSET(dset5_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float", HOFFSET(dset5_t, b), H5T_NATIVE_FLOAT);
- dataset = H5Dcreate(group, "dset5", type, space, H5P_DEFAULT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset5);
-
- H5Gunlink(group,"type4");
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
- H5Sclose(space);
- H5Gclose(group);
-
- H5Fclose(fid);
-
-}
-
-/*
- /
- / | \ \
- dset1 group1 type1 type2
- |
- dset2
-
-*/
-static void test_compound_dt2(void) { /* test compound data type */
- hid_t fid, group, dataset, space, type, create_plist, type2;
- hid_t array_dt;
-
- typedef struct {
- int a;
- float b;
- double c;
- } dset1_t;
- dset1_t dset1[10];
-
- typedef struct {
- int a;
- float b;
- } dset2_t;
- dset2_t dset2[10];
-
- typedef struct {
- int a[4];
- float b[5][6];
- } dset3_t;
-
- typedef struct {
- int a;
- float b;
- } dset4_t;
- dset4_t dset4[10];
-
- typedef struct {
- int a;
- float b;
- } dset5_t;
- dset5_t dset5[10];
-
- int i, ndims;
- const int perm[2]={0,1};
- hsize_t dim[2];
-
- hsize_t sdim, maxdim;
-
- sdim = 10;
- for (i = 0; i < (int)sdim; i++) {
- dset1[i].a = i;
- dset1[i].b = i*i;
- dset1[i].c = 1./(i+1);
-
- dset2[i].a = i;
- dset2[i].b = i+ i*0.1;
-
- dset4[i].a = i;
- dset4[i].b = i*1.0;
-
- dset5[i].a = i;
- dset5[i].b = i*1.0;
- }
-
- fid = H5Fcreate(FILE9, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
-
- sdim = 2;
- H5Pset_chunk(create_plist, 1, &sdim);
-
- sdim = 6;
- maxdim = H5S_UNLIMITED;
-
- space = H5Screate_simple(1, &sdim, &maxdim);
-
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset1[0]));
-
- H5Tinsert(type, "a_name", HOFFSET(dset1_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "b_name", HOFFSET(dset1_t, b), H5T_IEEE_F32BE);
- H5Tinsert(type, "c_name", HOFFSET(dset1_t, c), H5T_IEEE_F64BE);
-
- dataset = H5Dcreate(fid, "/dset1", type, space, create_plist);
-
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset1[0]));
-
- H5Tinsert(type2, "a_name", HOFFSET(dset1_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "b_name", HOFFSET(dset1_t, b), H5T_NATIVE_FLOAT);
- H5Tinsert(type2, "c_name", HOFFSET(dset1_t, c), H5T_NATIVE_DOUBLE);
-
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Sclose(space);
- H5Dclose(dataset);
-
- sdim = 6;
- maxdim = 10;
-
- space = H5Screate_simple(1, &sdim, &maxdim);
-
- /* shared data type 1 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset2_t));
- H5Tinsert(type, "int_name", HOFFSET(dset2_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float_name", HOFFSET(dset2_t, b), H5T_IEEE_F32BE);
- H5Tcommit(fid, "type1", type);
-
- group = H5Gcreate (fid, "/group1", 0);
-
- dataset = H5Dcreate(group, "dset2", type, space, create_plist);
-
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset2_t));
- H5Tinsert(type2, "int_name", HOFFSET(dset2_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float_name", HOFFSET(dset2_t, b), H5T_NATIVE_FLOAT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
-
-
- /* shared data type 2 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset3_t));
-
- ndims = 1; dim[0] = 4;
- array_dt=H5Tarray_create(H5T_STD_I32BE,ndims,dim,perm);
- H5Tinsert(type, "int_array", HOFFSET(dset3_t, a), array_dt);
- H5Tclose(array_dt);
-
- ndims = 2; dim[0] = 5; dim[1] = 6;
- array_dt=H5Tarray_create(H5T_IEEE_F32BE,ndims,dim,perm);
- H5Tinsert(type, "float_array", HOFFSET(dset3_t, b), array_dt);
- H5Tclose(array_dt);
-
- H5Tcommit(fid, "type2", type);
- H5Tclose(type);
-
- /* shared data type 3 */
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset4_t));
- H5Tinsert(type, "int", HOFFSET(dset4_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float", HOFFSET(dset4_t, b), H5T_IEEE_F32BE);
- H5Tcommit(group, "type3", type);
-
- dataset = H5Dcreate(group, "dset4", type, space, create_plist);
-
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset4_t));
- H5Tinsert(type2, "int", HOFFSET(dset4_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float", HOFFSET(dset4_t, b), H5T_NATIVE_FLOAT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset4);
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
- H5Gclose(group);
-
-
- /* unamed data type */
- group = H5Gcreate (fid, "/group2", 0);
-
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset5_t));
- H5Tinsert(type, "int", HOFFSET(dset5_t, a), H5T_STD_I32BE);
- H5Tinsert(type, "float", HOFFSET(dset5_t, b), H5T_IEEE_F32BE);
- H5Tcommit(group, "type4", type);
- dataset = H5Dcreate(group, "dset5", type, space, create_plist);
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset5_t));
- H5Tinsert(type2, "int", HOFFSET(dset5_t, a), H5T_NATIVE_INT);
- H5Tinsert(type2, "float", HOFFSET(dset5_t, b), H5T_NATIVE_FLOAT);
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset5);
-
- H5Gunlink(group,"type4");
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Dclose(dataset);
- H5Sclose(space);
- H5Gclose(group);
-
- H5Fclose(fid);
-
-}
-
-
-/*
-
-/ : g1 g2 attr1 attr2
-g1 : g1.1 g1.2
-g1.1 : dset1.1.1(attr1, attr2) dset1.1.2
-g1.2 : g1.2.1
-g1.2.1 : slink
-g2 : dset2.1 dset2.2
-
-*/
-
-static void test_all(void) {
-hid_t fid, group, attr, dataset, space;
-hsize_t dims[2];
-int data[2][2], dset1[10][10], dset2[20];
-char buf[60];
-int i, j;
-float dset2_1[10], dset2_2[3][5];
-
- fid = H5Fcreate(FILE7, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* create groups */
- group = H5Gcreate (fid, "/g1", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g2", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g1/g1.1", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g1/g1.2", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g1/g1.2/g1.2.1", 0);
- H5Gclose(group);
-
- /* root attributes */
- group = H5Gopen (fid, "/");
-
- dims[0] = 10;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (group, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT);
- sprintf(buf, "abcdefghi");
- H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
- H5Sclose(space);
- H5Aclose(attr);
-
- dims[0] = 2; dims[1] = 2;
- space = H5Screate_simple(2, dims, NULL);
- attr = H5Acreate (group, "attr2", H5T_STD_I32BE, space, H5P_DEFAULT);
- data[0][0] = 0; data[0][1] = 1; data[1][0] = 2; data[1][1] = 3;
- H5Awrite(attr, H5T_NATIVE_INT, data);
- H5Sclose(space);
- H5Aclose(attr);
-
- H5Gclose(group);
-
- group = H5Gopen (fid, "/g1/g1.1");
-
- /* dset1.1.1 */
- dims[0] = 10; dims[1] = 10;
- space = H5Screate_simple(2, dims, NULL);
- dataset = H5Dcreate(group, "dset1.1.1", H5T_STD_I32BE, space, H5P_DEFAULT);
- for (i = 0; i < 10; i++)
- for (j = 0; j < 10; j++)
- dset1[i][j] = j*i;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
- H5Sclose(space);
-
- /* attributes of dset1.1.1 */
- dims[0] = 27;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (dataset, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT);
- sprintf(buf, "1st attribute of dset1.1.1");
- H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
- H5Sclose(space);
- H5Aclose(attr);
-
- dims[0] = 27;
- space = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (dataset, "attr2", H5T_STD_I8BE, space, H5P_DEFAULT);
- sprintf(buf, "2nd attribute of dset1.1.1");
- H5Awrite(attr, H5T_NATIVE_SCHAR, buf);
- H5Sclose(space);
- H5Aclose(attr);
-
- H5Dclose(dataset);
-
- /* dset1.1.2 */
- dims[0] = 20;
- space = H5Screate_simple(1, dims, NULL);
- dataset = H5Dcreate(group, "dset1.1.2", H5T_STD_I32BE, space, H5P_DEFAULT);
- for (i = 0; i < 20; i++)
- dset2[i] = i;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
- H5Sclose(space);
- H5Dclose(dataset);
-
- H5Gclose(group);
-
- /* soft link */
- group = H5Gopen (fid, "/g1/g1.2/g1.2.1");
- H5Glink (group, H5G_LINK_SOFT, "somevalue", "slink");
- H5Gclose(group);
-
- group = H5Gopen (fid, "/g2");
-
- /* dset2.1 */
- dims[0] = 10;
- space = H5Screate_simple(1, dims, NULL);
- dataset = H5Dcreate(group, "dset2.1", H5T_IEEE_F32BE, space, H5P_DEFAULT);
- for (i = 0; i < 10; i++)
- dset2_1[i] = i*0.1+1;
- H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_1);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* dset2.2 */
- dims[0] = 3; dims[1] = 5;
- space = H5Screate_simple(2, dims, NULL);
- dataset = H5Dcreate(group, "dset2.2", H5T_IEEE_F32BE, space, H5P_DEFAULT);
- for (i = 0; i < 3; i++)
- for (j = 0; j < 5; j++)
- dset2_2[i][j] = (i+1)*j*0.1;
- H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_2);
- H5Sclose(space);
- H5Dclose(dataset);
-
- H5Gclose(group);
-
- H5Fclose(fid);
-
-}
-
-/*
- o
- /___\
- g1 o/ \o g2
- \___/
-
-
-o - group objects
-
-*/
-
-static void test_loop(void) {
-hid_t fid, group;
-
- fid = H5Fcreate(FILE10, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- group = H5Gcreate (fid, "/g1", 0);
- H5Gclose(group);
- group = H5Gcreate (fid, "/g2", 0);
- H5Gclose(group);
-
- H5Glink(fid, H5G_LINK_HARD, "/g2", "/g1/g1.1");
- H5Glink(fid, H5G_LINK_HARD, "/g1", "/g2/g2.1");
-
- H5Fclose(fid);
-}
-
-static void test_loop2(void) {
-hid_t fid, group;
-
- fid = H5Fcreate(FILE11, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* create group object g1 and implcit path from root object */
- group = H5Gcreate (fid, "/g1", 0);
- H5Gclose(group);
-
- /* create group object g2 and implcit path from root object */
- group = H5Gcreate (fid, "/g2", 0);
- H5Gclose(group);
-
- /* create path from object at /g1 to object at /g2 and name it g1.1 */
- H5Glink (fid, H5G_LINK_HARD, "/g2", "/g1/g1.1");
-
- /* create path from object at /g2 to object at /g1 and name it g2.1 */
- H5Glink (fid, H5G_LINK_SOFT, "/g1", "/g2/g2.1");
-
- H5Fclose(fid);
-
-}
-
-/*
- /
- | | | \ \ \
- g1 g2 g3 g4 g5 g6
- / \ | | \ \ \
- g1.1 g1.2 slink2 link3 dset2 slink4 dset3
- | | (g1) (dset2) (dset3)
- dset1 link1
- (dset1)
-*/
-
-static void test_many(void) {
- hid_t fid, group, attr, dataset, space, space2, type, create_plist, type2;
- hid_t array_dt;
- hsize_t dims[2];
- int data[2][2], dset2[10][10], dset3[10][10];
- double d[10];
-
- char buf[60];
- int i, j;
- int i0, i1, i2, i3;
- hsize_t sdim, maxdim;
-
- typedef struct { /* compound type has members with rank > 1 */
- int a[2][2][2][2]; /* arrays are 2x2x2x2 */
- double b[2][2][2][2];
- double c[2][2][2][2];
- } dset1_t;
- dset1_t dset1[6];
-
- hsize_t dim[4];
- int index[4] = {0,1,2,3}; /* normal indicies */
- const int perm[4] = {0,1,2,3}; /* the 0'th and the 3'rd indices are permuted */
-
- fid = H5Fcreate(FILE12, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- group = H5Gcreate (fid, "/g1", 0);
- H5Gclose(group);
-
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
-
- sdim = 2;
- H5Pset_chunk(create_plist, 1, &sdim);
-
- group = H5Gcreate (fid, "/g1/g1.1", 0);
-
- type = H5Tcreate (H5T_COMPOUND, sizeof(dset1[0]));
-
- dim[0] = dim[1] = dim[2] = dim[3] = 2;
- array_dt=H5Tarray_create(H5T_STD_I32BE,4,dim,perm);
- H5Tinsert(type, "a_array", HOFFSET(dset1_t, a), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_IEEE_F64BE,4,dim,perm);
- H5Tinsert(type, "b_array", HOFFSET(dset1_t, b), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_IEEE_F64BE,4,dim,perm);
- H5Tinsert(type, "c_array", HOFFSET(dset1_t, c), array_dt);
- H5Tclose(array_dt);
-
- type2 = H5Tcreate (H5T_COMPOUND, sizeof(dset1[0]));
-
- array_dt=H5Tarray_create(H5T_NATIVE_INT,4,dim,perm);
- H5Tinsert(type2, "a_array", HOFFSET(dset1_t, a), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_NATIVE_DOUBLE,4,dim,perm);
- H5Tinsert(type2, "b_array", HOFFSET(dset1_t, b), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_NATIVE_DOUBLE,4,dim,perm);
- H5Tinsert(type2, "c_array", HOFFSET(dset1_t, c), array_dt);
- H5Tclose(array_dt);
-
-
- /* dset1 */
- sdim = 6;
- maxdim = H5S_UNLIMITED;
- space = H5Screate_simple(1, &sdim, &maxdim);
- dataset = H5Dcreate(group, "dset1", type, space, create_plist);
-
- /* add attributes to dset1 */
- dims[0] = 10;
- space2 = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (dataset, "attr1", H5T_STD_I8BE, space2, H5P_DEFAULT);
- sprintf(buf, "abcdefghi");
- H5Awrite(attr, H5T_NATIVE_CHAR, buf);
- H5Sclose(space2);
- H5Aclose(attr);
-
- dims[0] = 2; dims[1] = 2;
- space2 = H5Screate_simple(2, dims, NULL);
- attr = H5Acreate (dataset, "attr2", H5T_STD_I32BE, space2, H5P_DEFAULT);
- data[0][0] = 0; data[0][1] = 1; data[1][0] = 2; data[1][1] = 3;
- H5Awrite(attr, H5T_NATIVE_INT, data);
- H5Sclose(space2);
- H5Aclose(attr);
-
- dims[0] = 10;
- space2 = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (dataset, "attr3", H5T_IEEE_F64BE, space2, H5P_DEFAULT);
- for (i = 0; i < 10; i++) d[i] = 0.1 * i;
- H5Awrite(attr, H5T_NATIVE_DOUBLE, d);
- H5Sclose(space2);
- H5Aclose(attr);
-
- for (j=0; j<(int)sdim; j++) {
- for (i3 = 0; i3 < 2; i3++) {
- index[perm[3]] = i3;
- for (i2 = 0; i2 < 2; i2++) {
- index[perm[2]] = i2;
- for (i1 = 0; i1 < 2; i1++) {
- index[perm[1]] = i1;
- for (i0 = 0; i0 < 2; i0++) {
- index[perm[0]] = i0;
-
- dset1[j].a[index[3]][index[2]][index[1]][index[0]] = i0+j;
- dset1[j].b[index[3]][index[2]][index[1]][index[0]] = (double)(i0+j);
-#if WIN32
- dset1[j].c[index[3]][index[2]][index[1]][index[0]] = (double)(i0+j+(signed __int64)sdim);
-#else
- dset1[j].c[index[3]][index[2]][index[1]][index[0]] = (double)(i0+j+sdim);
-#endif
- }
- }
- }
- }
- }
-
- H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
-
- H5Dclose(dataset);
- H5Sclose(space);
-
- H5Tclose(type);
- H5Tclose(type2);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g1/g1.2", 0);
- H5Glink (group, H5G_LINK_HARD, "/g1/g1.1/dset1", "link1");
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g2", 0);
- H5Glink (group, H5G_LINK_SOFT, "/g1", "slink2");
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g3", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g4", 0);
-
- /* dset2 */
- dims[0] = 10; dims[1] = 10;
- space = H5Screate_simple(2, dims, NULL);
-
- dataset = H5Dcreate(group, "dset2", H5T_STD_I32BE, space, H5P_DEFAULT);
- for (i = 0; i < 10; i++)
- for (j = 0; j < 10; j++)
- dset2[i][j] = j;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2);
-
- H5Dclose(dataset);
-
- H5Sclose(space);
- H5Gclose(group);
-
- group = H5Gopen(fid, "/g3");
- H5Glink (group, H5G_LINK_HARD, "/g4/dset2", "link3");
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g5", 0);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g6", 0);
- /* dset3 */
- dims[0] = 10; dims[1] = 10;
- space = H5Screate_simple(2, dims, NULL);
-
- dataset = H5Dcreate(group, "dset3", H5T_STD_I32BE, space, H5P_DEFAULT);
- for (i = 0; i < 10; i++)
- for (j = 0; j < 10; j++)
- dset3[i][j] = i;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset3);
-
- H5Dclose(dataset);
-
- H5Sclose(space);
- H5Gclose(group);
-
- group = H5Gopen(fid, "/g5");
- H5Glink (group, H5G_LINK_SOFT, "/g6/dset3", "slink4");
- H5Gclose(group);
-
- H5Fclose(fid);
-
-}
-static hid_t mkstr(int size, H5T_str_t pad) {
-hid_t type;
-
- if ((type=H5Tcopy(H5T_C_S1))<0) return -1;
- if (H5Tset_size(type, (size_t)size)<0) return -1;
- if (H5Tset_strpad(type, pad)<0) return -1;
-
- return type;
-}
-
-static void test_str(void) {
- hid_t fid, dataset, space, f_type, m_type, str_type, f_type2;
- hid_t array_dt;
-
- hsize_t dims1[] = { 3, 4};
- char string1[12][2] = {"s1","s2","s3","s4","s5","s6","s7","s8","s9",
- "s0","s1","s2"};
-
- hsize_t dims2[]={20};
- char string2[20][9] = {"ab cd ef1", "ab cd ef2", "ab cd ef3", "ab cd ef4",
- "ab cd ef5", "ab cd ef6", "ab cd ef7", "ab cd ef8",
- "ab cd ef9", "ab cd ef0", "ab cd ef1", "ab cd ef2",
- "ab cd ef3", "ab cd ef4", "ab cd ef5", "ab cd ef6",
- "ab cd ef7", "ab cd ef8", "ab cd ef9", "ab cd ef0"};
-
- hsize_t dims3[] = { 27};
- char string3[27][5] = {"abcd0", "abcd1", "abcd2", "abcd3",
- "abcd4", "abcd5", "abcd6", "abcd7",
- "abcd8", "abcd9", "abcd0", "abcd1",
- "abcd2", "abcd3", "abcd4", "abcd5",
- "abcd6", "abcd7", "abcd8", "abcd9",
- "abcd0", "abcd1", "abcd2", "abcd3",
- "abcd4", "abcd5", "abcd6"};
-
- int i, j, k, l;
-
- hsize_t dims4[] = { 3 };
- char string4[3][20] = { "s1234567890123456789", "s1234567890123456789",
- "s1234567890123456789"};
-
- hsize_t dims5[] = { 3, 6};
- typedef struct {
- int a[8][10];
- char s[12][32];
- } compound_t;
- compound_t comp1[3][6];
- hsize_t mdims[2];
-
- fid = H5Fcreate(FILE13, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* string 1 : nullterm string */
- space = H5Screate_simple(2, dims1, NULL);
- f_type = mkstr(5, H5T_STR_NULLTERM);
- m_type = mkstr(2, H5T_STR_NULLTERM);
- dataset = H5Dcreate(fid, "/string1", f_type, space, H5P_DEFAULT);
- H5Dwrite(dataset, m_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, string1);
- H5Tclose(m_type);
- H5Tclose(f_type);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* string 2 : space pad string */
- space = H5Screate_simple(1, dims2, NULL);
- f_type = mkstr(11, H5T_STR_SPACEPAD);
- m_type = mkstr(9, H5T_STR_NULLTERM);
- dataset = H5Dcreate(fid, "/string2", f_type, space, H5P_DEFAULT);
- H5Dwrite(dataset, m_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, string2);
- H5Tclose(m_type);
- H5Tclose(f_type);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* string 3 : null pad string */
- space = H5Screate_simple(1, dims3, NULL);
- f_type = mkstr(8, H5T_STR_NULLPAD);
- m_type = mkstr(5, H5T_STR_NULLTERM);
- dataset = H5Dcreate(fid, "/string3", f_type, space, H5P_DEFAULT);
- H5Dwrite(dataset, m_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, string3);
- H5Tclose(m_type);
- H5Tclose(f_type);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* string 4 : space pad long string */
- space = H5Screate_simple(1, dims4, NULL);
- f_type = mkstr(168, H5T_STR_SPACEPAD);
- m_type = mkstr(20, H5T_STR_NULLTERM);
- dataset = H5Dcreate(fid, "/string4", f_type, space, H5P_DEFAULT);
- H5Dwrite(dataset, m_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, string4);
- H5Tclose(m_type);
- H5Tclose(f_type);
- H5Sclose(space);
- H5Dclose(dataset);
-
- /* compound data */
- space = H5Screate_simple(2, dims5, NULL);
- f_type = H5Tcreate (H5T_COMPOUND, sizeof(compound_t));
- f_type2 = H5Tcreate (H5T_COMPOUND, sizeof(compound_t));
-
- mdims[0] = 8; mdims[1] = 10;
-
- array_dt=H5Tarray_create(H5T_STD_I32BE,2,mdims,NULL);
- H5Tinsert(f_type, "int_array", HOFFSET(compound_t, a), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(H5T_NATIVE_INT,2,mdims,NULL);
- H5Tinsert(f_type2, "int_array", HOFFSET(compound_t, a), array_dt);
- H5Tclose(array_dt);
-
- str_type = mkstr(32, H5T_STR_SPACEPAD);
- mdims[0] = 3; mdims[1] = 4;
-
- array_dt=H5Tarray_create(str_type,2,mdims,NULL);
- H5Tinsert(f_type, "string", HOFFSET(compound_t, s), array_dt);
- H5Tclose(array_dt);
-
- array_dt=H5Tarray_create(str_type,2,mdims,NULL);
- H5Tinsert(f_type2, "string", HOFFSET(compound_t, s), array_dt);
- H5Tclose(array_dt);
-
- for (i = 0; i < 3; i++)
- for (j = 0; j < 6; j++) {
- for (k = 0 ; k < 8; k++)
- for (l = 0; l < 10; l++)
- comp1[i][j].a[k][l] = (l+j+k) * (l+j+k);
- for (k = 0 ; k < 12; k++)
- sprintf(comp1[i][j].s[k], "abcdefgh12345678abcdefgh12345678");
- }
-
- dataset = H5Dcreate(fid, "/comp1", f_type, space, H5P_DEFAULT);
- H5Dwrite(dataset, f_type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, comp1);
-
- H5Tclose(str_type);
- H5Tclose(f_type);
- H5Tclose(f_type2);
- H5Sclose(space);
- H5Dclose(dataset);
-
- H5Fclose(fid);
-}
-
-/*
- /
- / / | \ \ \
- g1 g2 g3 g4 g5 g6
- | | | | \ \
- string1 string3 string5
- string2 string4 string6
-*/
-
-static void test_str2(void)
-{
-hid_t fid, group, attr, dataset, space, space2, mem_space, hyper_space;
-hid_t fxdlenstr, fxdlenstr2, memtype;
-hsize_t dims[1], size[1], stride[1], count[1], block[1];
-hssize_t start[1];
-
-
-int i;
-char buf[LENSTR+10];
-char buf2[3*LENSTR2];
-hsize_t sdim;
-
- fid = H5Fcreate(FILE14, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- fxdlenstr = H5Tcopy(H5T_C_S1);
- H5Tset_size(fxdlenstr, LENSTR);
- H5Tset_cset(fxdlenstr, H5T_CSET_ASCII);
- H5Tset_strpad(fxdlenstr, H5T_STR_NULLTERM);
-
- memtype = H5Tcopy(H5T_C_S1);
- H5Tset_size(memtype, LENSTR);
- H5Tset_cset(memtype, H5T_CSET_ASCII);
- H5Tset_strpad(memtype, H5T_STR_NULLTERM);
-
- sdim = 10;
- size[0] = sdim;
- space = H5Screate_simple(1, size, NULL);
- size[0] = 1;
- mem_space = H5Screate_simple(1,size,NULL);
- hyper_space = H5Scopy(space);
-
- /* dset1 */
-
- group = H5Gcreate (fid, "/g1", 0);
- dataset = H5Dcreate(group, "dset1", fxdlenstr, space, H5P_DEFAULT);
-
- /* add attributes to dset1 */
-
- fxdlenstr2 = H5Tcopy(H5T_C_S1);
- H5Tset_size(fxdlenstr2, LENSTR2);
- H5Tset_cset(fxdlenstr2, H5T_CSET_ASCII);
- H5Tset_strpad(fxdlenstr2, H5T_STR_NULLTERM);
-
- dims[0] = 3;
- space2 = H5Screate_simple(1, dims, NULL);
- attr = H5Acreate (dataset, "attr1", fxdlenstr2, space2, H5P_DEFAULT);
- sprintf(&(buf2[0*LENSTR2]), "0123456789");
- sprintf(&(buf2[1*LENSTR2]), "abcdefghij");
- sprintf(&(buf2[2*LENSTR2]), "ABCDEFGHIJ");
- H5Awrite(attr, fxdlenstr2, buf2);
- H5Sclose(space2);
- H5Tclose(fxdlenstr2);
- H5Aclose(attr);
-
- stride[0]=1;
- count[0]=1;
- block[0]=1;
-
- for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
- H5Dclose(dataset);
- H5Gclose(group);
-
- group = H5Gcreate (fid, "/g2", 0);
- dataset = H5Dcreate(group, "dset2", fxdlenstr, space, H5P_DEFAULT);
-
- for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLTERM of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
- H5Dclose(dataset);
- H5Gclose(group);
-
-
- H5Tclose(fxdlenstr);
- fxdlenstr = H5Tcopy(H5T_C_S1);
- H5Tset_size(fxdlenstr, LENSTR);
- H5Tset_cset(fxdlenstr, H5T_CSET_ASCII);
- H5Tset_strpad(fxdlenstr, H5T_STR_NULLPAD);
-
- group = H5Gcreate (fid, "/g3", 0);
- dataset = H5Dcreate(group, "dset3", fxdlenstr, space, H5P_DEFAULT);
-
- for (i = 0;(hsize_t) i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
- H5Dclose(dataset);
- H5Gclose(group);
-
-
- group = H5Gcreate (fid, "/g4", 0);
- dataset = H5Dcreate(group, "dset4", fxdlenstr, space, H5P_DEFAULT);
-
- for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_NULLPAD of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
- H5Dclose(dataset);
- H5Gclose(group);
-
- H5Tclose(fxdlenstr);
- fxdlenstr = H5Tcopy(H5T_C_S1);
- H5Tset_size(fxdlenstr, LENSTR);
- H5Tset_cset(fxdlenstr, H5T_CSET_ASCII);
- H5Tset_strpad(fxdlenstr, H5T_STR_SPACEPAD);
-
- group = H5Gcreate (fid, "/g5", 0);
- dataset = H5Dcreate(group, "dset5", fxdlenstr, space, H5P_DEFAULT);
-
- for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
- H5Dclose(dataset);
- H5Gclose(group);
-
-
- group = H5Gcreate (fid, "/g6", 0);
- dataset = H5Dcreate(group, "dset6", fxdlenstr, space, H5P_DEFAULT);
-
- for (i = 0; (hsize_t)i < sdim; i++) {
- start[0] = i;
- sprintf(buf,"This is row %1d of type H5T_STR_SPACEPAD of string array",i);
- H5Tset_size(memtype, HDstrlen(buf)+1);
- H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block);
- H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf);
- }
-
- H5Dclose(dataset);
- H5Tclose(fxdlenstr);
- H5Tclose(memtype);
- H5Sclose(mem_space);
- H5Sclose(hyper_space);
- H5Sclose(space);
- H5Fclose(fid);
-}
-
-static void test_enum(void)
-{
- /*some code is taken from enum.c in the test dir */
- hid_t file, type, space, dset;
- int val;
- enumtype data[] = {RED, GREEN, BLUE, GREEN, WHITE,
- WHITE, BLACK, GREEN, BLUE, RED,
- RED, BLUE, GREEN, BLACK, WHITE,
- RED, WHITE, GREEN, GREEN, BLUE};
- hsize_t size[1] = {NELMTS(data)};
-
- file = H5Fcreate(FILE15,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
-
- type = H5Tcreate(H5T_ENUM, sizeof(enumtype));
- H5Tenum_insert(type, "RED", (val = 0, &val));
- H5Tenum_insert(type, "GREEN", (val = 1, &val));
- H5Tenum_insert(type, "BLUE", (val = 2, &val));
- H5Tenum_insert(type, "WHITE", (val = 3, &val));
- H5Tenum_insert(type, "BLACK", (val = 4, &val));
- H5Tcommit(file, "enum normal", type);
-
- space = H5Screate_simple(1,size,NULL);
- dset = H5Dcreate(file,"table",type, space, H5P_DEFAULT);
- H5Dwrite(dset,type,space,space,H5P_DEFAULT,data);
-
- H5Dclose(dset);
- H5Sclose(space);
- H5Fclose(file);
-}
-
-static void test_objref(void)
-{
-/*some code is taken from enum.c in the test dir */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
-
- hid_t group; /* Group ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Datatype ID */
- hsize_t dims1[] = {SPACE1_DIM1};
- hobj_ref_t *wbuf, /* buffer to write to disk */
- *rbuf, /* buffer read from disk */
- *tbuf; /* temp. buffer read from disk */
- uint32_t *tu32; /* Temporary pointer to uint32 data */
- intn i; /* counting variables */
- const char *write_comment="Foo!"; /* Comments for group */
-
- /* Allocate write & read buffers */
- wbuf=malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
- rbuf=malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
- tbuf=malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
-
- /* Create file */
- fid1 = H5Fcreate(FILE16, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
-
- /* Create a group */
- group=H5Gcreate(fid1,"Group1",(size_t)-1);
-
- /* Set group's comment */
- H5Gset_comment(group,".",write_comment);
-
- /* Create a dataset (inside Group1) */
- dataset=H5Dcreate(group,"Dataset1",H5T_STD_U32BE,sid1,H5P_DEFAULT);
-
- for(tu32=(uint32_t *)((void*)wbuf),i=0; i<SPACE1_DIM1; i++)
- *tu32++=i*3;
-
- /* Write selection to disk */
- H5Dwrite(dataset,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
-
- /* Close Dataset */
- H5Dclose(dataset);
-
- /* Create another dataset (inside Group1) */
- dataset=H5Dcreate(group,"Dataset2",H5T_STD_U8BE,sid1,H5P_DEFAULT);
-
- /* Close Dataset */
- H5Dclose(dataset);
-
- /* Create a datatype to refer to */
- tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
-
- /* Insert fields */
- H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_STD_I32BE);
-
- H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_IEEE_F32BE);
-
- H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_IEEE_F32BE);
-
- /* Save datatype for later */
- H5Tcommit (group, "Datatype1", tid1);
-
- /* Close datatype */
- H5Tclose(tid1);
-
- /* Close group */
- H5Gclose(group);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
-
- /* Create reference to dataset */
- H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
- H5Rget_object_type(dataset,&wbuf[0]);
-
- /* Create reference to dataset */
- H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
-
- H5Rget_object_type(dataset,&wbuf[1]);
-
- /* Create reference to group */
- H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
-
- H5Rget_object_type(dataset,&wbuf[2]);
-
-
- /* Create reference to named datatype */
- H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
-
- H5Rget_object_type(dataset,&wbuf[3]);
-
-
- /* Write selection to disk */
- H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
-
-
- /* Close disk dataspace */
- H5Sclose(sid1);
-
- /* Close Dataset */
- H5Dclose(dataset);
-
- /* Close file */
- H5Fclose(fid1);
-
- /* Free memory buffers */
- free(wbuf);
- free(rbuf);
- free(tbuf);
-
-}
-
-static void test_datareg(void)
-{
- /*some code is taken from enum.c in the test dir */
-
- hid_t fid1; /* HDF5 File IDs */
- hid_t dset1, /* Dataset ID */
- dset2; /* Dereferenced dataset ID */
- hid_t sid1, /* Dataspace ID #1 */
- sid2; /* Dataspace ID #2 */
- hsize_t dims1[] = {SPACE1_DIM1},
- dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
- hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
- hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
- hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
- hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
- hssize_t coord1[POINT1_NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */
- hdset_reg_ref_t *wbuf, /* buffer to write to disk */
- *rbuf; /* buffer read from disk */
- uint8_t *dwbuf, /* Buffer for writing numeric data to disk */
- *drbuf; /* Buffer for reading numeric data from disk */
- uint8_t *tu8; /* Temporary pointer to uint8 data */
- intn i; /* counting variables */
-
- /* Allocate write & read buffers */
- wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
- rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
- dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2);
- drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2);
-
- /* Create file */
- fid1 = H5Fcreate(FILE17, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
-
- /* Create a dataset */
- dset2=H5Dcreate(fid1,"Dataset2",H5T_STD_U8BE,sid2,H5P_DEFAULT);
-
- for(tu8=dwbuf,i=0; i<SPACE2_DIM1*SPACE2_DIM2; i++)
- *tu8++=i*3;
-
- /* Write selection to disk */
- H5Dwrite(dset2,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
-
- /* Close Dataset */
- H5Dclose(dset2);
-
- /* Create dataspace for the reference dataset */
- sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
-
- /* Create a dataset */
- dset1=H5Dcreate(fid1,"Dataset1",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
-
- /* Create references */
-
- /* Select 6x6 hyperslab for first reference */
- start[0]=2; start[1]=2;
- stride[0]=1; stride[1]=1;
- count[0]=6; count[1]=6;
- block[0]=1; block[1]=1;
- H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
-
- H5Sget_select_npoints(sid2);
-
- /* Store first dataset region */
- H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
-
- /* Select sequence of ten points for second reference */
- coord1[0][0]=6; coord1[0][1]=9;
- coord1[1][0]=2; coord1[1][1]=2;
- coord1[2][0]=8; coord1[2][1]=4;
- coord1[3][0]=1; coord1[3][1]=6;
- coord1[4][0]=2; coord1[4][1]=8;
- coord1[5][0]=3; coord1[5][1]=2;
- coord1[6][0]=0; coord1[6][1]=4;
- coord1[7][0]=9; coord1[7][1]=0;
- coord1[8][0]=7; coord1[8][1]=1;
- coord1[9][0]=3; coord1[9][1]=3;
- H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
-
- H5Sget_select_npoints(sid2);
-
- /* Store second dataset region */
- H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
-
- /* Write selection to disk */
- H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
-
- /* Close disk dataspace */
- H5Sclose(sid1);
-
- /* Close Dataset */
- H5Dclose(dset1);
-
- /* Close uint8 dataset dataspace */
- H5Sclose(sid2);
-
- /* Close file */
- H5Fclose(fid1);
-
- /* Free memory buffers */
- free(wbuf);
- free(rbuf);
- free(dwbuf);
- free(drbuf);
-}
-
-/*taken from Elena's compound test file*/
-static void test_nestcomp(void)
-{
- /* Compound memeber of the compound datatype*/
- typedef struct cmp_t {
- char a;
- float b[2];
- } cmp_t;
-
- /* First structure and dataset*/
- typedef struct s1_t {
- int a;
- float b;
- double c;
- cmp_t d;
- } s1_t;
- hid_t cmp_tid; /* Handle for the compound datatype */
- hid_t char_id; /* Handle for the string datatype */
- hid_t array_dt;
- hsize_t array_dims[] = {2}; /* Dataspace dimensions */
- int ndims = 1; /* Number of dimensions in the array field */
-
- s1_t s1[10];
- hid_t s1_tid; /* File datatype identifier */
-
- int i;
- hid_t file, dataset, space; /* Handles */
- herr_t status;
- hsize_t dim[] = {10}; /* Dataspace dimensions */
-
- char datasetname[] = "ArrayOfStructures";
-
-
- /*
- * Initialize the data
- */
- for (i = 0; i< 10; i++) {
- s1[i].a = i;
- s1[i].b = i*i;
- s1[i].c = 1./(i+1);
- s1[i].d.a = 65 + i;
- s1[i].d.b[0] = -100.;
- s1[i].d.b[1] = 100.;
- }
-
- /*
- * Create the data space.
- */
- space = H5Screate_simple(1, dim, NULL);
-
- /*
- * Create the file.
- */
- file = H5Fcreate(FILE18, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create the memory data type.
- */
- /*
- * Create a datatype for compound field first.
- */
- cmp_tid = H5Tcreate (H5T_COMPOUND, sizeof(cmp_t));
-
- /* We are using C string of length one to represent "real" character */
- char_id = H5Tcopy(H5T_C_S1);
- H5Tset_strpad(char_id, H5T_STR_NULLTERM);
- H5Tinsert(cmp_tid, "char_name", HOFFSET(cmp_t, a), char_id);
-
- array_dt=H5Tarray_create(H5T_NATIVE_FLOAT,ndims,array_dims,NULL);
- H5Tinsert(cmp_tid, "array_name", HOFFSET(cmp_t, b), array_dt);
- H5Tclose(array_dt);
-
- s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
- H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
- H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
- H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
-
- /* Insert compound memeber created above */
- H5Tinsert(s1_tid, "d_name", HOFFSET(s1_t, d), cmp_tid);
-
- /*
- * Create the dataset.
- */
- dataset = H5Dcreate(file, datasetname, s1_tid, space, H5P_DEFAULT);
-
- /*
- * Wtite data to the dataset;
- */
- status = H5Dwrite(dataset, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1);
- if (status < 0)
- fprintf(stderr, "test_nestcomp H5Dwrite failed\n");
-
- /*
- * Release resources
- */
- H5Tclose(s1_tid);
- H5Tclose(cmp_tid);
- H5Tclose(char_id);
- H5Sclose(space);
- H5Dclose(dataset);
- H5Fclose(file);
-}
-
-static void test_opaque(void)
-{
- hid_t file, type, dataset, space;
- char test[100][2];
- int x;
- hsize_t dim = 2;
-
- for (x = 0; x < 100; x++){
- test[x][0] = x;
- test[x][1] = 99 - x;
- }
-
- /*
- * Create the data space.
- */
- space = H5Screate_simple(1, &dim, NULL);
-
- /*
- * Create the file.
- */
- file = H5Fcreate(FILE19, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create the memory datatype.
- */
- type = H5Tcreate (H5T_OPAQUE, sizeof(char)*100*2);
- H5Tset_tag(type, "test opaque type");
-
- /*
- * Create the dataset.
- */
- dataset = H5Dcreate(file, "opaque test", type, space, H5P_DEFAULT);
-
- /*
- * Write data to the dataset;
- */
- H5Dwrite(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, test);
-
- H5Tclose(type);
- H5Sclose(space);
- H5Dclose(dataset);
- H5Fclose(file);
-}
-
-static void test_bitfields(void)
-{
- hid_t file, grp=-1, type=-1, space=-1, dset=-1;
- size_t i;
- hsize_t nelmts;
- unsigned char buf[32];
-
- file = H5Fcreate(FILE20, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- if ((grp=H5Gcreate(file, "typetests", 0))<0) goto error;
-
- /* bitfield_1 */
- nelmts = sizeof(buf);
- if ((type=H5Tcopy(H5T_STD_B8LE))<0 ||
- (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
- (dset=H5Dcreate(grp, "bitfield_1", type, space, H5P_DEFAULT))<0)
- goto error;
-
- for (i=0; i<sizeof buf; i++) buf[i] = (unsigned char)0xff ^ (unsigned char)i;
- if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0)
- goto error;
- if (H5Sclose(space)<0) goto error;
- if (H5Tclose(type)<0) goto error;
- if (H5Dclose(dset)<0) goto error;
-
- /* bitfield_2 */
- nelmts = sizeof(buf)/2;
- if ((type=H5Tcopy(H5T_STD_B16LE))<0 ||
- (space=H5Screate_simple(1, &nelmts, NULL))<0 ||
- (dset=H5Dcreate(grp, "bitfield_2", type, space, H5P_DEFAULT))<0)
- goto error;
- for (i=0; i<sizeof buf; i++) buf[i] = (unsigned char)0xff ^ (unsigned char)i;
- if (H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0)
- goto error;
- if (H5Sclose(space)<0) goto error;
- if (H5Tclose(type)<0) goto error;
- if (H5Dclose(dset)<0) goto error;
- if (H5Gclose(grp)<0) goto error;
- H5Fclose(file);
-
- error:
- H5E_BEGIN_TRY {
- H5Gclose(grp);
- H5Tclose(type);
- H5Sclose(space);
- H5Dclose(dset);
- } H5E_END_TRY;
-}
-
-static void test_vldatatypes(void)
-{
- hvl_t adata, wdata[SPACE1_DIM1];
- hid_t file, dset, space, type;
- hsize_t dims[] = { SPACE1_DIM1 };
- int i;
- herr_t ret=0;
-
- ret = ret; /* so that compiler won't complain "is set but never used" */
- file = H5Fcreate(FILE21, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Allocate and initialize VL dataset to write */
- for(i = 0; i < SPACE1_DIM1; i++) {
- int j;
-
- wdata[i].p = malloc((i + 1) * sizeof(int));
- wdata[i].len = i + 1;
-
- for (j = 0; j < i + 1; j++)
- ((int *)wdata[i].p)[j] = i * 10 + j;
- }
-
- /* write out the integers in little-endian format */
- space = H5Screate_simple(SPACE1_RANK, dims, NULL);
- type = H5Tvlen_create(H5T_NATIVE_INT);
- dset = H5Dcreate(file, "Dataset1.0", type, space, H5P_DEFAULT);
- ret = H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
- ret = H5Dvlen_reclaim(type, space, H5P_DEFAULT, wdata);
-
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
- ret = H5Sclose(space);
-
- /* Allocate and initialize VL dataset to write */
- for(i = 0; i < SPACE1_DIM1; i++) {
- int j;
-
- wdata[i].p = malloc((i + 1) * sizeof(float));
- wdata[i].len = i + 1;
-
- for (j = 0; j < i + 1; j++)
- ((float *)wdata[i].p)[j] = i * 10 + ((float)j) / 10.0;
- }
-
- /* write out the floats in little-endian format */
- space = H5Screate_simple(SPACE1_RANK, dims, NULL);
- type = H5Tvlen_create(H5T_NATIVE_FLOAT);
- dset = H5Dcreate(file, "Dataset2.0", type, space, H5P_DEFAULT);
- ret = H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
- ret = H5Dvlen_reclaim(type, space, H5P_DEFAULT, wdata);
-
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
- ret = H5Sclose(space);
-
- /* Allocate and initialize a scalar VL dataset to write */
- adata.p = malloc(37 * sizeof(int));
- adata.len = 37;
-
- for (i = 0; i < 37; i++)
- ((int *)adata.p)[i] = i * 2;
-
- /* write out scalar VL dataset in little-endian format */
- space = H5Screate_simple(0, NULL, NULL);
- type = H5Tvlen_create(H5T_NATIVE_INT);
- dset = H5Dcreate(file, "Dataset3.0", type, space, H5P_DEFAULT);
- ret = H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, &adata);
- ret = H5Dvlen_reclaim(type, space, H5P_DEFAULT, &adata);
-
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
- ret = H5Sclose(space);
- ret = H5Fclose(file);
-}
-
-static void test_vldatatypes2(void)
-{
- hvl_t wdata[SPACE1_DIM1]; /* Information to write */
- hvl_t *t1; /* Temporary pointer to VL information */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
- uintn i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
-
- ret = ret; /* so that compiler won't complain "is set but never used" */
-
- /* Allocate and initialize VL data to write */
- for(i=0; i<SPACE1_DIM1; i++) {
- wdata[i].p=malloc((i+1)*sizeof(hvl_t));
- if(wdata[i].p==NULL) {
- printf("Cannot allocate memory for VL data! i=%u\n",i);
- return;
- } /* end if */
- wdata[i].len=i+1;
- for(t1=wdata[i].p,j=0; j<(i+1); j++, t1++) {
- t1->p=malloc((j+1)*sizeof(unsigned int));
- if(t1->p==NULL) {
- printf("Cannot allocate memory for VL data! i=%u, j=%u\n",i,j);
- return;
- } /* end if */
- t1->len=j+1;
- for(k=0; k<(j+1); k++)
- ((unsigned int *)t1->p)[k]=i*100+j*10+k;
- } /* end for */
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE22, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
-
- /* Create a VL datatype to refer to */
- tid1 = H5Tvlen_create (H5T_NATIVE_UINT);
-
- /* Create the base VL type */
- tid2 = H5Tvlen_create (tid1);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid2,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Reclaim the write VL data */
- ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid2);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-
-}
-
-static void test_vldatatypes3(void)
-{
- typedef struct { /* Struct that the VL sequences are composed of */
- int i;
- float f;
- hvl_t v;
- } s1;
- s1 wdata[SPACE1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
- uintn i,j; /* counting variables */
- herr_t ret; /* Generic return value */
-
- ret = ret; /* so that compiler won't complain "is set but never used" */
-
- /* Allocate and initialize VL data to write */
- for(i=0; i<SPACE1_DIM1; i++) {
- wdata[i].i=i*10;
- wdata[i].f=(i*20)/3.0;
- wdata[i].v.p=malloc((i+1)*sizeof(unsigned int));
- wdata[i].v.len=i+1;
- for(j=0; j<(i+1); j++)
- ((unsigned int *)wdata[i].v.p)[j]=i*10+j;
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE23, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
-
- /* Create a VL datatype to refer to */
- tid1 = H5Tvlen_create (H5T_NATIVE_UINT);
-
- /* Create the base compound type */
- tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1));
-
- /* Insert fields */
- ret=H5Tinsert(tid2, "i", HOFFSET(s1, i), H5T_NATIVE_INT);
- ret=H5Tinsert(tid2, "f", HOFFSET(s1, f), H5T_NATIVE_FLOAT);
- ret=H5Tinsert(tid2, "v", HOFFSET(s1, v), tid1);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid2,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid2,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Reclaim the write VL data */
- ret=H5Dvlen_reclaim(tid2,sid1,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid2);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_vldatatypes4(void)
-{
- typedef struct { /* Struct that the VL sequences are composed of */
- int i;
- float f;
- } s1;
- hvl_t wdata[SPACE1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1, tid2; /* Datatype IDs */
- hsize_t dims1[] = {SPACE1_DIM1};
- uintn i,j; /* counting variables */
- herr_t ret; /* Generic return value */
-
- ret = ret; /* so that compiler won't complain "is set but never used" */
-
- /* Allocate and initialize VL data to write */
- for(i=0; i<SPACE1_DIM1; i++) {
- wdata[i].p=malloc((i+1)*sizeof(s1));
- wdata[i].len=i+1;
- for(j=0; j<(i+1); j++) {
- ((s1 *)wdata[i].p)[j].i=i*10+j;
- ((s1 *)wdata[i].p)[j].f=(i*20+j)/3.0;
- } /* end for */
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE24, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
-
- /* Create the base compound type */
- tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1));
-
- /* Insert fields */
- ret=H5Tinsert(tid2, "i", HOFFSET(s1, i), H5T_NATIVE_INT);
- ret=H5Tinsert(tid2, "f", HOFFSET(s1, f), H5T_NATIVE_FLOAT);
-
- /* Create a datatype to refer to */
- tid1 = H5Tvlen_create (tid2);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Reclaim the write VL data */
- ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Tclose(tid2);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_array1(void)
-{
- int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- intn i,j; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Allocate and initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++)
- wdata[i][j]=i*10+j;
-
- /* Create file */
- fid1 = H5Fcreate(FILE25, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a datatype to refer to */
- tid1 = H5Tarray_create (H5T_NATIVE_INT,ARRAY1_RANK,tdims1,NULL);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_array2(void)
-{
- int wdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information to write */
- hid_t fid; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims2[] = {ARRAY2_DIM1,ARRAY2_DIM2,ARRAY2_DIM3};
- intn i,j,k,l; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Allocate and initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY2_DIM1; j++)
- for(k=0; k<ARRAY2_DIM2; k++)
- for(l=0; l<ARRAY2_DIM3; l++)
- wdata[i][j][k][l]=i*1000+j*100+k*10+l;
-
- /* Create file */
- fid = H5Fcreate(FILE26, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a datatype to refer to */
- tid = H5Tarray_create (H5T_NATIVE_INT,ARRAY2_RANK,tdims2,NULL);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid,"Dataset1",tid,sid,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid);
- ret = H5Sclose(sid);
- ret = H5Fclose(fid);
-}
-
-static void test_array3(void)
-{
- int wdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information to write */
- hid_t fid; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid1; /* 1-D array Datatype ID */
- hid_t tid2; /* 2-D array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- hsize_t tdims2[] = {ARRAY3_DIM1,ARRAY3_DIM2};
- intn i,j,k,l; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Allocate and initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++)
- for(k=0; k<ARRAY3_DIM1; k++)
- for(l=0; l<ARRAY3_DIM2; l++)
- wdata[i][j][k][l]=i*1000+j*100+k*10+l;
-
- /* Create file */
- fid = H5Fcreate(FILE27, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a 2-D datatype to refer to */
- tid2 = H5Tarray_create (H5T_NATIVE_INT,ARRAY3_RANK,tdims2,NULL);
-
- /* Create a 1-D datatype to refer to */
- tid1 = H5Tarray_create (tid2,ARRAY1_RANK,tdims1,NULL);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid,"Dataset1",tid1,sid,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Tclose(tid2);
- ret = H5Sclose(sid);
- ret = H5Fclose(fid);
-}
-
-static void test_array4(void)
-{
- typedef struct { /* Typedef for compound datatype */
- int i;
- float f;
- } s1_t;
- s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* Compound Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- intn i,j; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++) {
- wdata[i][j].i=i*10+j;
- wdata[i][j].f=i*2.5+j;
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE28, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a compound datatype to refer to */
- tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
-
- /* Insert integer field */
- ret = H5Tinsert (tid2, "i", HOFFSET(s1_t,i), H5T_NATIVE_INT);
-
- /* Insert float field */
- ret = H5Tinsert (tid2, "f", HOFFSET(s1_t,f), H5T_NATIVE_FLOAT);
-
- /* Create an array datatype to refer to */
- tid1 = H5Tarray_create (tid2,ARRAY1_RANK,tdims1,NULL);
-
- /* Close compound datatype */
- ret=H5Tclose(tid2);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_array5(void)
-{
- typedef struct { /* Typedef for compound datatype */
- int i;
- float f[ARRAY1_DIM1];
- } s1_t;
- s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* Compound Datatype ID */
- hid_t tid3; /* Nested Array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- intn i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++) {
- wdata[i][j].i=i*10+j;
- for(k=0; k<ARRAY1_DIM1; k++)
- wdata[i][j].f[k]=i*10+j*2.5+k;
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE29, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a compound datatype to refer to */
- tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
-
- /* Insert integer field */
- ret = H5Tinsert (tid2, "i", HOFFSET(s1_t,i), H5T_NATIVE_INT);
-
- /* Create an array of floats datatype */
- tid3 = H5Tarray_create (H5T_NATIVE_FLOAT,ARRAY1_RANK,tdims1,NULL);
-
- /* Insert float array field */
- ret = H5Tinsert (tid2, "f", HOFFSET(s1_t,f), tid3);
-
- /* Close array of floats field datatype */
- ret=H5Tclose(tid3);
-
- /* Create an array datatype to refer to */
- tid1 = H5Tarray_create (tid2,ARRAY1_RANK,tdims1,NULL);
-
- /* Close compound datatype */
- ret=H5Tclose(tid2);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_array6(void)
-{
- hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* VL Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- intn i,j,k; /* counting variables */
- herr_t ret; /* Generic return value */
-
- /* Initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++) {
- wdata[i][j].p=malloc((i+j+1)*sizeof(unsigned int));
- wdata[i][j].len=i+j+1;
- for(k=0; k<(i+j+1); k++)
- ((unsigned int *)wdata[i][j].p)[k]=i*100+j*10+k;
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE30, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create a compound datatype to refer to */
- tid2 = H5Tvlen_create(H5T_NATIVE_UINT);
-
- /* Create an array datatype to refer to */
- tid1 = H5Tarray_create (tid2,ARRAY1_RANK,tdims1,NULL);
-
- /* Close VL datatype */
- ret=H5Tclose(tid2);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Reclaim the write VL data */
- ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_array7(void)
-{
- hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
- hid_t fid1; /* HDF5 File IDs */
- hid_t dataset; /* Dataset ID */
- hid_t sid1; /* Dataspace ID */
- hid_t tid1; /* Array Datatype ID */
- hid_t tid2; /* VL Datatype ID */
- hid_t tid3; /* Nested Array Datatype ID */
- hsize_t sdims1[] = {SPACE1_DIM1};
- hsize_t tdims1[] = {ARRAY1_DIM1};
- intn i,j,k,l; /* Index variables */
- herr_t ret; /* Generic return value */
-
- /* Initialize array data to write */
- for(i=0; i<SPACE1_DIM1; i++)
- for(j=0; j<ARRAY1_DIM1; j++) {
- wdata[i][j].p=malloc((i+j+1)*(sizeof(unsigned int)*ARRAY1_DIM1));
- wdata[i][j].len=i+j+1;
- for(k=0; k<(i+j+1); k++)
- for(l=0; l<ARRAY1_DIM1; l++)
- ((unsigned int *)wdata[i][j].p)[k*ARRAY1_DIM1+l]=i*1000+j*100+k*10+l;
- } /* end for */
-
- /* Create file */
- fid1 = H5Fcreate(FILE31, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /* Create dataspace for datasets */
- sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
-
- /* Create the nested array datatype to refer to */
- tid3 = H5Tarray_create(H5T_NATIVE_UINT,ARRAY1_RANK,tdims1,NULL);
-
- /* Create a VL datatype of 1-D arrays to refer to */
- tid2 = H5Tvlen_create(tid3);
-
- /* Close nested array datatype */
- ret=H5Tclose(tid3);
-
- /* Create an array datatype to refer to */
- tid1 = H5Tarray_create (tid2,ARRAY1_RANK,tdims1,NULL);
-
- /* Close VL datatype */
- ret=H5Tclose(tid2);
-
- /* Create a dataset */
- dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
-
- /* Write dataset to disk */
- ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
-
- /* Reclaim the write VL data */
- ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,wdata);
-
- /* Close Dataset */
- ret = H5Dclose(dataset);
- ret = H5Tclose(tid1);
- ret = H5Sclose(sid1);
- ret = H5Fclose(fid1);
-}
-
-static void test_empty(void)
-{
- typedef struct {
- int a;
- float b;
- char c;
- } empty_struct;
- hid_t file, dset, space, type;
- hsize_t dims[] = { SPACE1_DIM1 };
- herr_t ret=0;
-
- ret = ret; /* so that compiler won't complain "is set but never used" */
- file = H5Fcreate(FILE32, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- space = H5Screate_simple(SPACE1_RANK, dims, NULL);
-
- /* write out an empty vlen dataset */
- type = H5Tvlen_create(H5T_NATIVE_INT);
- dset = H5Dcreate(file, "Dataset1.0", type, space, H5P_DEFAULT);
- /* Don't write any data */
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
-
- /* write out an empty native integer dataset dataset */
- dset = H5Dcreate(file, "Dataset2.0", H5T_NATIVE_INT, space, H5P_DEFAULT);
- /* Don't write any data */
- ret = H5Dclose(dset);
-
- /* write out an empty native floating-point dataset dataset */
- dset = H5Dcreate(file, "Dataset3.0", H5T_NATIVE_FLOAT, space, H5P_DEFAULT);
- /* Don't write any data */
- ret = H5Dclose(dset);
-
- /* write out an empty array dataset */
- type = H5Tarray_create(H5T_NATIVE_INT,SPACE1_RANK,dims,NULL);
- dset = H5Dcreate(file, "Dataset4.0", type, space, H5P_DEFAULT);
- /* Don't write any data */
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
-
- /* write out an empty compound dataset */
- type = H5Tcreate(H5T_COMPOUND,sizeof(empty_struct));
- H5Tinsert(type, "a", HOFFSET(empty_struct, a),H5T_NATIVE_INT);
- H5Tinsert(type, "b", HOFFSET(empty_struct, b),H5T_NATIVE_FLOAT);
- H5Tinsert(type, "c", HOFFSET(empty_struct, c),H5T_NATIVE_CHAR);
- dset = H5Dcreate(file, "Dataset5.0", type, space, H5P_DEFAULT);
- /* Don't write any data */
- ret = H5Dclose(dset);
- ret = H5Tclose(type);
-
- ret = H5Sclose(space);
-
- ret = H5Fclose(file);
-}
-
-int main(void)
-{
- test_group();
- test_attribute();
- test_softlink();
- test_dataset();
- test_hardlink();
- test_compound_dt();
- test_all();
- test_loop();
-
- test_dataset2();
- test_compound_dt2();
- test_loop2();
- test_many();
-
- test_str();
- test_str2();
-
- test_enum();
-
- test_objref();
- test_datareg();
-
- test_nestcomp();
-
- test_opaque();
-
- test_bitfields();
-
- test_vldatatypes();
- test_vldatatypes2();
- test_vldatatypes3();
- test_vldatatypes4();
-
- test_array1();
- test_array2();
- test_array3();
- test_array4();
- test_array5();
- test_array6();
- test_array7();
-
- test_empty();
-
- return 0;
-}
diff --git a/tools/h5import.c b/tools/h5import.c
deleted file mode 100644
index e896feb..0000000
--- a/tools/h5import.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 1998 NCSA
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Thursday, June 11, 1998
- *
- * Purpose: Create an hdf5 file with a 1d dataset of uint8.
- */
-
-/* See H5private.h for how to include system headers */
-#include <hdf5.h>
-#ifdef H5_STDC_HEADERS
-# include <fcntl.h>
-# include <string.h>
-# include <stdlib.h>
-# include <stdio.h>
-#endif
-
-#ifdef H5_HAVE_UNISTD_H
-# include <sys/types.h>
-# include <unistd.h>
-#endif
-
-#ifdef H5_HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
-#ifdef WIN32
-#include <io.h>
-#endif
-
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: Print a usage message and exit with non-zero status
- *
- * Return: never returns
- *
- * Programmer: Robb Matzke
- * Thursday, June 11, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-usage (const char *argv0)
-{
- fprintf (stderr, "Usage: %s -f HDF5-FILE FILES...\n", argv0);
- exit (1);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose:
- *
- * Return: Success: 0
- *
- * Failure: 1
- *
- * Programmer: Robb Matzke
- * Thursday, June 11, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-main (int argc, char *argv[])
-{
- hid_t file, space=-1, dset=-1;
- const char *output_name, *dset_name;
- int argno, fd=-1;
- hsize_t size[1];
- struct stat sb;
-
- /* Parse arguments */
- if (argc<4) usage (argv[0]);
- if (strcmp (argv[1], "-f")) usage (argv[0]);
- output_name = argv[2];
-
- /* create the file */
- H5E_BEGIN_TRY {
- if ((file = H5Fcreate (output_name, H5F_ACC_EXCL,
- H5P_DEFAULT, H5P_DEFAULT))<0 &&
- (file = H5Fopen (output_name, H5F_ACC_RDWR, H5P_DEFAULT)<0)) {
- fprintf (stderr, "%s: unable to create or open hdf5 file\n",
- output_name);
- exit (1);
- }
- } H5E_END_TRY;
-
- /* process files from command-line */
- for (argno=3; argno<argc; argno++) {
-
- /* Open the file */
- if ((dset_name=strrchr (argv[argno], '/'))) dset_name++;
- else dset_name = argv[argno];
- fprintf (stderr, "%s\n", dset_name);
- if ((fd=open (argv[argno], O_RDONLY))<0) {
- perror (argv[argno]);
- goto next;
- }
- if (fstat (fd, &sb)<0) {
- perror (argv[argno]);
- goto next;
- }
-
- /* Data space */
- size[0] = sb.st_size;
- if ((space = H5Screate_simple (1, size, size))<0) goto next;
-
- /* Dataset */
- if ((dset=H5Dcreate (file, dset_name, H5T_NATIVE_SCHAR,
- space, H5P_DEFAULT))<0) goto next;
-
-
-
- next:
- if (fd>=0) close (fd);
- fd = -1;
- H5E_BEGIN_TRY {
- if (space>=0) {
- H5Sclose (space);
- space = -1;
- }
- if (dset>=0) {
- H5Dclose (dset);
- dset = -1;
- }
- } H5E_END_TRY;
- }
-
- /* Close the file */
- H5Fclose (file);
- return 0;
-}
diff --git a/tools/h5ls.c b/tools/h5ls.c
deleted file mode 100644
index 7a6ff39..0000000
--- a/tools/h5ls.c
+++ /dev/null
@@ -1,2166 +0,0 @@
-/*
- * Copyright (C) 1998 NCSA
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Monday, March 23, 1998
- */
-
-
-/*
- * We include the private header file so we can get to the uniform
- * programming environment it declares. Other than that, h5ls only calls
- * HDF5 API functions (except for H5G_basename())
- */
-#include <H5private.h>
-#include <h5tools.h>
-
-/*
- * If defined then include the file name as part of the object name when
- * printing full object names. Otherwise leave the file name off.
- */
-#define H5LS_PREPEND_FILENAME
-
-/* Command-line switches */
-static int verbose_g = 0; /*lots of extra output */
-static int width_g = 80; /*output width in characters */
-static hbool_t address_g = FALSE; /*print raw data addresses */
-static hbool_t data_g = FALSE; /*display dataset values? */
-static hbool_t label_g = FALSE; /*label compound values? */
-static hbool_t string_g = FALSE; /*print 1-byte numbers as ASCII? */
-static hbool_t fullname_g = FALSE; /*print full path names */
-static hbool_t recursive_g = FALSE; /*recursive descent listing */
-static hbool_t grp_literal_g = FALSE; /*list group, not contents */
-static hbool_t hexdump_g = FALSE; /*show data as raw hexadecimal */
-static hbool_t show_errors_g = FALSE; /*print HDF5 error messages */
-static hbool_t simple_output_g = FALSE; /*make output more machine-readable */
-
-/* Info to pass to the iteration functions */
-typedef struct iter_t {
- const char *container; /*full name of the container object */
-} iter_t;
-
-/* Table containing object id and object name */
-static struct {
- int nalloc; /*number of slots allocated */
- int nobjs; /*number of objects */
- struct {
- unsigned long id[2]; /*object number */
- char *name; /*full object name */
- } *obj;
-} idtab_g;
-
-/* Information about how to display each type of object */
-static struct dispatch_t {
- const char *name;
- hid_t (*open)(hid_t loc, const char *name);
- herr_t (*close)(hid_t obj);
- herr_t (*list1)(hid_t obj);
- herr_t (*list2)(hid_t obj, const char *name);
-} dispatch_g[H5G_NTYPES];
-
-#define DISPATCH(TYPE,NAME,OPEN,CLOSE,LIST1,LIST2) { \
- dispatch_g[TYPE].name = (NAME); \
- dispatch_g[TYPE].open = (OPEN); \
- dispatch_g[TYPE].close = (CLOSE); \
- dispatch_g[TYPE].list1 = (LIST1); \
- dispatch_g[TYPE].list2 = (LIST2); \
-}
-
-static herr_t list (hid_t group, const char *name, void *cd);
-static void display_type(hid_t type, int ind);
-static char *fix_name(const char *path, const char *base);
-
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: Prints a usage message on stderr and then returns.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, July 16, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-usage (const char *progname)
-{
- fprintf(stderr, "\
-usage: %s [OPTIONS] [OBJECTS...]\n\
- OPTIONS\n\
- -h, -?, --help Print a usage message and exit\n\
- -a, --address Print addresses for raw data\n\
- -d, --data Print the values of datasets\n\
- -e, --errors Show all HDF5 error reporting\n\
- -f, --full Print full path names instead of base names\n\
- -g, --group Show information about a group, not its contents\n\
- -l, --label Label members of compound datasets\n\
- -r, --recursive List all groups recursively, avoiding cycles\n\
- -s, --string Print 1-byte integer datasets as ASCII\n\
- -S, --simple Use a machine-readable output format\n\
- -wN, --width=N Set the number of columns of output\n\
- -v, --verbose Generate more verbose output\n\
- -V, --version Print version number and exit\n\
- -x, --hexdump Show raw data in hexadecimal format\n\
-\n\
- OBJECTS\n\
- Each object consists of an HDF5 file name optionally followed by a\n\
- slash and an object name within the file (if no object is specified\n\
- within the file then the contents of the root group are displayed).\n\
- The file name may include a printf(3C) integer format such as\n\
- \"%%05d\" to open a file family.\n",
- progname);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: sym_insert
- *
- * Purpose: Add a symbol to the table.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-sym_insert(H5G_stat_t *sb, const char *name)
-{
- int n;
-
- /*
- * Don't add it if the link count is 1 because such an object can only
- * have one name.
- */
- if (sb->nlink<2) return;
-
- /* Extend the table */
- if (idtab_g.nobjs>=idtab_g.nalloc) {
- idtab_g.nalloc = MAX(256, 2*idtab_g.nalloc);
- idtab_g.obj = realloc(idtab_g.obj,
- idtab_g.nalloc*sizeof(idtab_g.obj[0]));
- }
-
- /* Insert the entry */
- n = idtab_g.nobjs++;
- idtab_g.obj[n].id[0] = sb->objno[0];
- idtab_g.obj[n].id[1] = sb->objno[1];
- idtab_g.obj[n].name = malloc(strlen(name)+1);
- strcpy(idtab_g.obj[n].name, name);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: sym_lookup
- *
- * Purpose: Find another name for the specified object.
- *
- * Return: Success: Ptr to another name.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-sym_lookup(H5G_stat_t *sb)
-{
- int n;
-
- if (sb->nlink<2) return NULL; /*only one name possible*/
- for (n=0; n<idtab_g.nobjs; n++) {
- if (idtab_g.obj[n].id[0]==sb->objno[0] &&
- idtab_g.obj[n].id[1]==sb->objno[1]) {
- return idtab_g.obj[n].name;
- }
- }
- return NULL;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_string
- *
- * Purpose: Print a string value by escaping unusual characters. If
- * STREAM is null then we only count how large the output would
- * be.
- *
- * Return: Number of characters printed.
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-display_string(FILE *stream, const char *s, hbool_t escape_spaces)
-{
- int nprint=0;
-
- for (/*void*/; s && *s; s++) {
- switch (*s) {
- case '"':
- if (stream) fprintf(stream, "\\\"");
- nprint += 2;
- break;
- case '\\':
- if (stream) fprintf(stream, "\\\\");
- nprint += 2;
- break;
- case '\b':
- if (stream) fprintf(stream, "\\b");
- nprint += 2;
- break;
- case '\f':
- if (stream) fprintf(stream, "\\f");
- nprint += 2;
- break;
- case '\n':
- if (stream) fprintf(stream, "\\n");
- nprint += 2;
- break;
- case '\r':
- if (stream) fprintf(stream, "\\r");
- nprint += 2;
- break;
- case '\t':
- if (stream) fprintf(stream, "\\t");
- nprint += 2;
- break;
- case ' ':
- if (escape_spaces) {
- if (stream) fprintf(stream, "\\ ");
- nprint += 2;
- } else {
- if (stream) fprintf(stream, " ");
- nprint++;
- }
- break;
- default:
- if (isprint((int)*s)) {
- if (stream) putc(*s, stream);
- nprint++;
- } else {
- if (stream) {
- fprintf(stream, "\\%03o", *((const unsigned char*)s));
- }
- nprint += 4;
- }
- break;
- }
- }
- return nprint;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_native_type
- *
- * Purpose: Prints the name of a native C data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed.
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-06-11
- * Added the C9x types, but we still prefer to display the types
- * from the C language itself (like `int' vs. `int32_t').
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_native_type(hid_t type, int UNUSED ind)
-{
- if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
- printf("native signed char");
- } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
- printf("native unsigned char");
- } else if (H5Tequal(type, H5T_NATIVE_INT)) {
- printf("native int");
- } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
- printf("native unsigned int");
- } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
- printf("native short");
- } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
- printf("native unsigned short");
- } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
- printf("native long");
- } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
- printf("native unsigned long");
- } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
- printf("native long long");
- } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
- printf("native unsigned long long");
- } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
- printf("native float");
- } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
- printf("native double");
- } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) {
- printf("native long double");
- } else if (H5Tequal(type, H5T_NATIVE_INT8)) {
- printf("native int8_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT8)) {
- printf("native uint8_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT16)) {
- printf("native int16_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT16)) {
- printf("native uint16_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT32)) {
- printf("native int32_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT32)) {
- printf("native uint32_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT64)) {
- printf("native int64_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT64)) {
- printf("native uint64_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8)) {
- printf("native int_least8_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8)) {
- printf("native uint_least8_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16)) {
- printf("native int_least16_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16)) {
- printf("native uint_least16_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32)) {
- printf("native int_least32_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32)) {
- printf("native uint_least32_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64)) {
- printf("native int_least64_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64)) {
- printf("native uint_least64_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_FAST8)) {
- printf("native int_fast8_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8)) {
- printf("native uint_fast8_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_FAST16)) {
- printf("native int_fast16_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16)) {
- printf("native uint_fast16_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_FAST32)) {
- printf("native int_fast32_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32)) {
- printf("native uint_fast32_t");
- } else if (H5Tequal(type, H5T_NATIVE_INT_FAST64)) {
- printf("native int_fast64_t");
- } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64)) {
- printf("native uint_fast64_t");
- } else if (H5Tequal(type, H5T_NATIVE_B8)) {
- printf("native 8-bit field");
- } else if (H5Tequal(type, H5T_NATIVE_B16)) {
- printf("native 16-bit field");
- } else if (H5Tequal(type, H5T_NATIVE_B32)) {
- printf("native 32-bit field");
- } else if (H5Tequal(type, H5T_NATIVE_B64)) {
- printf("native 64-bit field");
- } else if (H5Tequal(type, H5T_NATIVE_HSIZE)) {
- printf("native hsize_t");
- } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) {
- printf("native hssize_t");
- } else if (H5Tequal(type, H5T_NATIVE_HERR)) {
- printf("native herr_t");
- } else if (H5Tequal(type, H5T_NATIVE_HBOOL)) {
- printf("native hbool_t");
- } else {
- return FALSE;
- }
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_ieee_type
- *
- * Purpose: Print the name of an IEEE floating-point data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_ieee_type(hid_t type, int UNUSED ind)
-{
- if (H5Tequal(type, H5T_IEEE_F32BE)) {
- printf("IEEE 32-bit big-endian float");
- } else if (H5Tequal(type, H5T_IEEE_F32LE)) {
- printf("IEEE 32-bit little-endian float");
- } else if (H5Tequal(type, H5T_IEEE_F64BE)) {
- printf("IEEE 64-bit big-endian float");
- } else if (H5Tequal(type, H5T_IEEE_F64LE)) {
- printf("IEEE 64-bit little-endian float");
- } else {
- return FALSE;
- }
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_precision
- *
- * Purpose: Prints information on the next line about precision and
- * padding if the precision is less than the total data type
- * size.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-display_precision(hid_t type, int ind)
-{
- size_t prec; /*precision */
- H5T_pad_t plsb, pmsb; /*lsb and msb padding */
- const char *plsb_s=NULL; /*lsb padding string */
- const char *pmsb_s=NULL; /*msb padding string */
- size_t nbits; /*number of bits */
-
- /*
- * If the precision is less than the total size then show the precision
- * and offset on the following line. Also display the padding
- * information.
- */
- if (8*H5Tget_size(type)!=(prec=H5Tget_precision(type))) {
- printf("\n%*s(%lu bit%s of precision beginning at bit %lu)",
- ind, "", (unsigned long)prec, 1==prec?"":"s",
- (unsigned long)H5Tget_offset(type));
-
- H5Tget_pad(type, &plsb, &pmsb);
- if (H5Tget_offset(type)>0) {
- switch (plsb) {
- case H5T_PAD_ZERO:
- plsb_s = "zero";
- break;
- case H5T_PAD_ONE:
- plsb_s = "one";
- break;
- case H5T_PAD_BACKGROUND:
- plsb_s = "bkg";
- break;
- case H5T_PAD_ERROR:
- case H5T_NPAD:
- plsb_s = "unknown";
- break;
- }
- }
- if (H5Tget_offset(type)+prec<8*H5Tget_size(type)) {
- switch (pmsb) {
- case H5T_PAD_ZERO:
- pmsb_s = "zero";
- break;
- case H5T_PAD_ONE:
- pmsb_s = "one";
- break;
- case H5T_PAD_BACKGROUND:
- pmsb_s = "bkg";
- break;
- case H5T_PAD_ERROR:
- case H5T_NPAD:
- pmsb_s = "unknown";
- break;
- }
- }
- if (plsb_s || pmsb_s) {
- printf("\n%*s(", ind, "");
- if (plsb_s) {
- nbits = H5Tget_offset(type);
- printf("%lu %s bit%s at bit 0",
- (unsigned long)nbits, plsb_s, 1==nbits?"":"s");
- }
- if (plsb_s && pmsb_s) printf(", ");
- if (pmsb_s) {
- nbits = 8*H5Tget_size(type)-(H5Tget_offset(type)+prec);
- printf("%lu %s bit%s at bit %lu",
- (unsigned long)nbits, pmsb_s, 1==nbits?"":"s",
- (unsigned long)(8*H5Tget_size(type)-nbits));
- }
- printf(")");
- }
- }
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_int_type
- *
- * Purpose: Print the name of an integer data type. Common information
- * like number of bits, byte order, and sign scheme appear on
- * the first line. Additional information might appear in
- * parentheses on the following lines.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_int_type(hid_t type, int ind)
-{
- H5T_order_t order; /*byte order value */
- const char *order_s=NULL; /*byte order string */
- H5T_sign_t sign; /*sign scheme value */
- const char *sign_s=NULL; /*sign scheme string */
-
- if (H5T_INTEGER!=H5Tget_class(type)) return FALSE;
-
- /* Byte order */
- if (H5Tget_size(type)>1) {
- order = H5Tget_order(type);
- if (H5T_ORDER_LE==order) {
- order_s = " little-endian";
- } else if (H5T_ORDER_BE==order) {
- order_s = " big-endian";
- } else if (H5T_ORDER_VAX==order) {
- order_s = " mixed-endian";
- } else {
- order_s = " unknown-byte-order";
- }
- } else {
- order_s = "";
- }
-
- /* Sign */
- if ((sign=H5Tget_sign(type))>=0) {
- if (H5T_SGN_NONE==sign) {
- sign_s = " unsigned";
- } else if (H5T_SGN_2==sign) {
- sign_s = "";
- } else {
- sign_s = " unknown-sign";
- }
- } else {
- sign_s = " unknown-sign";
- }
-
- /*
- * Print size, order, and sign on first line, precision and padding
- * information on the subsequent lines
- */
- printf("%lu-bit%s%s integer",
- (unsigned long)(8*H5Tget_size(type)), order_s, sign_s);
- display_precision(type, ind);
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_float_type
- *
- * Purpose: Print info about a floating point data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_float_type(hid_t type, int ind)
-{
- H5T_order_t order; /*byte order value */
- const char *order_s=NULL; /*byte order string */
- size_t spos; /*sign bit position */
- size_t esize, epos; /*exponent size and position */
- size_t msize, mpos; /*significand size and position */
- size_t ebias; /*exponent bias */
- H5T_norm_t norm; /*significand normalization */
- const char *norm_s=NULL; /*normalization string */
- H5T_pad_t pad; /*internal padding value */
- const char *pad_s=NULL; /*internal padding string */
-
- if (H5T_FLOAT!=H5Tget_class(type)) return FALSE;
-
- /* Byte order */
- if (H5Tget_size(type)>1) {
- order = H5Tget_order(type);
- if (H5T_ORDER_LE==order) {
- order_s = " little-endian";
- } else if (H5T_ORDER_BE==order) {
- order_s = " big-endian";
- } else if (H5T_ORDER_VAX==order) {
- order_s = " mixed-endian";
- } else {
- order_s = " unknown-byte-order";
- }
- } else {
- order_s = "";
- }
-
- /*
- * Print size and byte order on first line, precision and padding on
- * subsequent lines.
- */
- printf("%lu-bit%s floating-point",
- (unsigned long)(8*H5Tget_size(type)), order_s);
- display_precision(type, ind);
-
- /* Print sizes, locations, and other information about each field */
- H5Tget_fields (type, &spos, &epos, &esize, &mpos, &msize);
- ebias = H5Tget_ebias(type);
- norm = H5Tget_norm(type);
- switch (norm) {
- case H5T_NORM_IMPLIED:
- norm_s = ", msb implied";
- break;
- case H5T_NORM_MSBSET:
- norm_s = ", msb always set";
- break;
- case H5T_NORM_NONE:
- norm_s = ", no normalization";
- break;
- case H5T_NORM_ERROR:
- norm_s = ", unknown normalization";
- break;
- }
- printf("\n%*s(significant for %lu bit%s at bit %lu%s)", ind, "",
- (unsigned long)msize, 1==msize?"":"s", (unsigned long)mpos,
- norm_s);
- printf("\n%*s(exponent for %lu bit%s at bit %lu, bias is 0x%lx)",
- ind, "", (unsigned long)esize, 1==esize?"":"s",
- (unsigned long)epos, (unsigned long)ebias);
- printf("\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos);
-
- /* Display internal padding */
- if (1+esize+msize<H5Tget_precision(type)) {
- pad = H5Tget_inpad(type);
- switch (pad) {
- case H5T_PAD_ZERO:
- pad_s = "zero";
- break;
- case H5T_PAD_ONE:
- pad_s = "one";
- break;
- case H5T_PAD_BACKGROUND:
- pad_s = "bkg";
- break;
- case H5T_PAD_ERROR:
- case H5T_NPAD:
- pad_s = "unknown";
- break;
- }
- printf("\n%*s(internal padding bits are %s)", ind, "", pad_s);
- }
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_cmpd_type
- *
- * Purpose: Print info about a compound data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_cmpd_type(hid_t type, int ind)
-{
- char *name=NULL; /*member name */
- int ndims; /*dimensionality */
- hsize_t dims[H5S_MAX_RANK]; /*dimensions */
- size_t size; /*total size of type in bytes */
- int perm[H5S_MAX_RANK]; /*index permutation */
- hid_t subtype; /*member data type */
- int i, j, n; /*miscellaneous counters */
-
-
- if (H5T_COMPOUND!=H5Tget_class(type)) return FALSE;
- printf("struct {");
- for (i=0; i<H5Tget_nmembers(type); i++) {
-
- /* Name and offset */
- name = H5Tget_member_name(type, i);
- printf("\n%*s\"", ind+4, "");
- n = display_string(stdout, name, FALSE);
- printf("\"%*s +%-4lu ", MAX(0, 16-n), "",
- (unsigned long)H5Tget_member_offset(type, i));
- free(name);
-
- /* Grab member's type */
- subtype = H5Tget_member_type(type, i);
-
- /* Dimensions and permutation */
- if(H5Tget_class(subtype)==H5T_ARRAY) {
- ndims = H5Tget_array_ndims(subtype);
- H5Tget_array_dims(subtype, dims, perm);
- } /* end if */
- else
- ndims=0;
-
- if (ndims>0) {
- printf("[");
- for (j=0; j<ndims; j++)
- printf("%s%lu", j?",":"", (unsigned long)(dims[j]));
- printf("]");
-
- for (j=0; j<ndims; j++)
- if (perm[j]!=j)
- break;
-
- if (j<ndims) {
- printf("x[");
- for (j=0; j<ndims; j++)
- printf("%s%d", j?",":"", perm[j]);
- printf("]");
- }
- printf(" ");
- }
-
- /* Data type */
- display_type(subtype, ind+4);
- H5Tclose(subtype);
- }
- size = H5Tget_size(type);
- printf("\n%*s} %lu byte%s",
- ind, "", (unsigned long)size, 1==size?"":"s");
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_enum_type
- *
- * Purpose: Print info about an enumeration data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Wednesday, December 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_enum_type(hid_t type, int ind)
-{
- char **name=NULL; /*member names */
- unsigned char *value=NULL; /*value array */
- int nmembs; /*number of members */
- int nchars; /*number of output characters */
- hid_t super; /*enum base integer type */
- hid_t native=-1; /*native integer data type */
- size_t dst_size; /*destination value type size */
- int i; /*miscellaneous counters */
- size_t j;
-
- if (H5T_ENUM!=H5Tget_class(type)) return FALSE;
- nmembs = H5Tget_nmembers(type);
- super = H5Tget_super(type);
- printf("enum ");
- display_type(super, ind+4);
- printf(" {");
-
- /*
- * Determine what data type to use for the native values. To simplify
- * things we entertain three possibilities:
- * 1. long_long -- the largest native signed integer
- * 2. unsigned long_long -- the largest native unsigned integer
- * 3. raw format
- */
- if (H5Tget_size(type)<=sizeof(long_long)) {
- dst_size = sizeof(long_long);
- if (H5T_SGN_NONE==H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
- }
- } else {
- dst_size = H5Tget_size(type);
- }
-
- /* Get the names and raw values of all members */
- assert(nmembs>0);
- name = calloc((size_t)nmembs, sizeof(char*));
- value = calloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size));
- for (i=0; i<nmembs; i++) {
- name[i] = H5Tget_member_name(type, i);
- H5Tget_member_value(type, i, value+i*H5Tget_size(type));
- }
-
- /* Convert values to native data type */
- if (native>0) H5Tconvert(super, native, (hsize_t)nmembs, value, NULL, H5P_DEFAULT);
-
- /* Sort members by increasing value */
- /*not implemented yet*/
-
- /* Print members */
- for (i=0; i<nmembs; i++) {
- printf("\n%*s", ind+4, "");
- nchars = display_string(stdout, name[i], TRUE);
- printf("%*s = ", MAX(0, 16-nchars), "");
-
- if (native<0) {
- printf("0x");
- for (j=0; j<dst_size; j++) {
- printf("%02x", value[i*dst_size+j]);
- }
- } else if (H5T_SGN_NONE==H5Tget_sign(native)) {
- printf("%"PRINTF_LL_WIDTH"u",
- *((unsigned long_long*)((void*)(value+i*dst_size))));
- } else {
- printf("%"PRINTF_LL_WIDTH"d",
- *((long_long*)((void*)(value+i*dst_size))));
- }
- }
-
- /* Release resources */
- for (i=0; i<nmembs; i++) free(name[i]);
- free(name);
- free(value);
- H5Tclose(super);
-
- if (0==nmembs) printf("\n%*s <empty>", ind+4, "");
- printf("\n%*s}", ind, "");
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_string_type
- *
- * Purpose: Print information about a string data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_string_type(hid_t type, int UNUSED ind)
-{
- H5T_str_t pad;
- const char *pad_s=NULL;
- H5T_cset_t cset;
- const char *cset_s=NULL;
-
- if (H5T_STRING!=H5Tget_class(type)) return FALSE;
-
- /* Padding */
- pad = H5Tget_strpad(type);
- switch (pad) {
- case H5T_STR_NULLTERM:
- pad_s = "null-terminated";
- break;
- case H5T_STR_NULLPAD:
- pad_s = "null-padded";
- break;
- case H5T_STR_SPACEPAD:
- pad_s = "space-padded";
- break;
- case H5T_STR_RESERVED_3:
- case H5T_STR_RESERVED_4:
- case H5T_STR_RESERVED_5:
- case H5T_STR_RESERVED_6:
- case H5T_STR_RESERVED_7:
- case H5T_STR_RESERVED_8:
- case H5T_STR_RESERVED_9:
- case H5T_STR_RESERVED_10:
- case H5T_STR_RESERVED_11:
- case H5T_STR_RESERVED_12:
- case H5T_STR_RESERVED_13:
- case H5T_STR_RESERVED_14:
- case H5T_STR_RESERVED_15:
- case H5T_STR_ERROR:
- pad_s = "unknown-format";
- break;
- }
-
- /* Character set */
- cset = H5Tget_cset(type);
- switch (cset) {
- case H5T_CSET_ASCII:
- cset_s = "ASCII";
- break;
- case H5T_CSET_RESERVED_1:
- case H5T_CSET_RESERVED_2:
- case H5T_CSET_RESERVED_3:
- case H5T_CSET_RESERVED_4:
- case H5T_CSET_RESERVED_5:
- case H5T_CSET_RESERVED_6:
- case H5T_CSET_RESERVED_7:
- case H5T_CSET_RESERVED_8:
- case H5T_CSET_RESERVED_9:
- case H5T_CSET_RESERVED_10:
- case H5T_CSET_RESERVED_11:
- case H5T_CSET_RESERVED_12:
- case H5T_CSET_RESERVED_13:
- case H5T_CSET_RESERVED_14:
- case H5T_CSET_RESERVED_15:
- case H5T_CSET_ERROR:
- cset_s = "unknown-character-set";
- break;
- }
-
- printf("%lu-byte %s %s string",
- (unsigned long)H5Tget_size(type), pad_s, cset_s);
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_reference_type
- *
- * Purpose: Prints information about a reference data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-06-04
- * Knows about object and dataset region references.
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_reference_type(hid_t type, int UNUSED ind)
-{
- if (H5T_REFERENCE!=H5Tget_class(type)) return FALSE;
-
- if (H5Tequal(type, H5T_STD_REF_OBJ)) {
- printf("object reference");
- } else if (H5Tequal(type, H5T_STD_REF_DSETREG)) {
- printf("dataset region reference");
- } else {
- printf("%lu-byte unknown reference",
- (unsigned long)H5Tget_size(type));
- }
-
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_opaque_type
- *
- * Purpose: Prints information about an opaque data type.
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE, nothing printed
- *
- * Programmer: Robb Matzke
- * Monday, June 7, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_opaque_type(hid_t type, int ind)
-{
- char *tag;
- size_t size;
-
- if (H5T_OPAQUE!=H5Tget_class(type)) return FALSE;
-
- size = H5Tget_size(type);
- printf("%lu-byte opaque type", (unsigned long)size);
- if ((tag=H5Tget_tag(type))) {
- printf("\n%*s(tag = \"", ind, "");
- display_string(stdout, tag, FALSE);
- printf("\")");
- free(tag);
- }
- return TRUE;
-}
-
-/*-------------------------------------------------------------------------
- * Function: display_vlen_type
- *
- * Purpose: Print information about a variable-length type
- *
- * Return: Success: TRUE
- *
- * Failure: FALSE
- *
- * Programmer: Robb Matzke
- * Friday, December 1, 2000
- *
- * Modifications:
- *-------------------------------------------------------------------------
- */
-static hbool_t
-display_vlen_type(hid_t type, int ind)
-{
- hid_t super;
-
- if (H5T_VLEN!=H5Tget_class(type)) return FALSE;
-
- printf("variable length of\n%*s", ind+4, "");
- super = H5Tget_super(type);
- display_type(super, ind+4);
- H5Tclose(super);
- return TRUE;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_type
- *
- * Purpose: Prints a data type definition. The definition is printed
- * without any leading space or trailing line-feed (although
- * there might be line-feeds inside the type definition). The
- * first line is assumed to have IND characters before it on
- * the same line (printed by the caller).
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-06-11
- * Prints the OID of shared data types.
- *
- *-------------------------------------------------------------------------
- */
-static void
-display_type(hid_t type, int ind)
-{
- H5T_class_t data_class = H5Tget_class(type);
- H5G_stat_t sb;
-
- /* Bad data type */
- if (type<0) {
- printf("<ERROR>");
- return;
- }
-
- /* Shared? If so then print the type's OID */
- if (H5Tcommitted(type)) {
- if (H5Gget_objinfo(type, ".", FALSE, &sb)>=0) {
- printf("shared-%lu:%lu:%lu:%lu ",
- sb.fileno[1], sb.fileno[0],
- sb.objno[1], sb.objno[0]);
- } else {
- printf("shared ");
- }
- }
-
- /* Print the type */
- if (display_native_type(type, ind) ||
- display_ieee_type(type, ind) ||
- display_int_type(type, ind) ||
- display_float_type(type, ind) ||
- display_cmpd_type(type, ind) ||
- display_enum_type(type, ind) ||
- display_string_type(type, ind) ||
- display_reference_type(type, ind) ||
- display_vlen_type(type, ind) ||
- display_opaque_type(type, ind)) {
- return;
- }
-
- /* Unknown type */
- printf("%lu-byte class-%u unknown",
- (unsigned long)H5Tget_size(type),
- (unsigned)data_class);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: dump_dataset_values
- *
- * Purpose: Prints all values of a dataset.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Tuesday, July 21, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-09-27
- * Understands the simple_output_g switch which causes data to
- * be displayed in a more machine-readable format.
- *-------------------------------------------------------------------------
- */
-static void
-dump_dataset_values(hid_t dset)
-{
- hid_t f_type = H5Dget_type(dset);
- size_t size = H5Tget_size(f_type);
- h5dump_t info;
- char string_prefix[64];
- static char fmt_double[16], fmt_float[16];
-
- /* Set to all default values and then override */
- memset(&info, 0, sizeof info);
-
- if (simple_output_g) {
- info.idx_fmt = "";
- info.line_ncols = 65535; /*something big*/
- info.line_per_line = 1;
- info.line_multi_new = 0;
- info.line_pre = " ";
- info.line_cont = " ";
-
- info.arr_pre = "";
- info.arr_suf = "";
- info.arr_sep = " ";
-
- info.cmpd_pre = "";
- info.cmpd_suf = "";
- info.cmpd_sep = " ";
-
- if (label_g) info.cmpd_name = "%s=";
-
- info.elmt_suf1 = " ";
- info.str_locale = ESCAPE_HTML;
-
- } else {
- info.idx_fmt = "(%s)";
- info.line_ncols = width_g;
- info.line_multi_new = 1;
- if (label_g) info.cmpd_name = "%s=";
- info.line_pre = " %s ";
- info.line_cont = " %s ";
- info.str_repeat = 8;
- }
-
- /* Floating point types should display full precision */
- sprintf(fmt_float, "%%1.%dg", FLT_DIG);
- info.fmt_float = fmt_float;
- sprintf(fmt_double, "%%1.%dg", DBL_DIG);
- info.fmt_double = fmt_double;
-
- info.dset_format = "DSET-%lu:%lu:%lu:%lu-";
- info.dset_hidefileno = 0;
-
- info.obj_format = "-%lu:%lu:%lu:%lu";
- info.obj_hidefileno = 0;
-
- info.dset_blockformat_pre = "%sBlk%lu: ";
- info.dset_ptformat_pre = "%sPt%lu: ";
-
- info.line_indent = "";
-
- if (hexdump_g) {
- /*
- * Print all data in hexadecimal format if the `-x' or `--hexdump'
- * command line switch was given.
- */
- info.raw = TRUE;
- } else if (string_g && 1==size && H5T_INTEGER==H5Tget_class(f_type)) {
- /*
- * Print 1-byte integer data as an ASCI character string instead of
- * integers if the `-s' or `--string' command-line option was given.
- */
- info.ascii = TRUE;
- info.elmt_suf1 = "";
- info.elmt_suf2 = "";
- strcpy(string_prefix, info.line_pre);
- strcat(string_prefix, "\"");
- info.line_pre = string_prefix;
- info.line_suf = "\"";
- }
-
- /*
- * Print all the values.
- */
- printf(" Data:\n");
- if (h5dump_dset(stdout, &info, dset, -1, -1)<0) {
- printf(" Unable to print data.\n");
- }
-
- H5Tclose(f_type);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: list_attr
- *
- * Purpose: Prints information about attributes.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Friday, June 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data)
-{
- hid_t attr, space, type, p_type;
- hsize_t size[64], nelmts=1;
- int ndims, i, n;
- size_t need;
- void *buf;
- h5dump_t info;
-
- printf(" Attribute: ");
- n = display_string(stdout, attr_name, TRUE);
- printf("%*s", MAX(0, 9-n), "");
- if ((attr = H5Aopen_name(obj, attr_name))) {
- space = H5Aget_space(attr);
- type = H5Aget_type(attr);
-
- /* Data space */
- ndims = H5Sget_simple_extent_dims(space, size, NULL);
- if (0==ndims) {
- puts(" scalar");
- } else {
- printf(" {");
- for (i=0; i<ndims; i++) {
- HDfprintf(stdout, "%s%Hu", i?", ":"", size[i]);
- nelmts *= size[i];
- }
- puts("}");
- }
-
- /* Data type */
- printf(" Type: ");
- display_type(type, 15);
- putchar('\n');
-
- /* Data */
- memset(&info, 0, sizeof info);
- info.line_multi_new = 1;
- if (nelmts<5) {
- info.idx_fmt = "";
- info.line_1st = " Data: ";
- info.line_pre = " ";
- info.line_cont = " ";
- info.str_repeat = 8;
-
- } else {
- printf(" Data:\n");
- info.idx_fmt = "(%s)";
- info.line_pre = " %s ";
- info.line_cont = " %s ";
- info.str_repeat = 8;
- }
- info.line_ncols = width_g;
- if (label_g) info.cmpd_name = "%s=";
- if (string_g && 1==H5Tget_size(type) &&
- H5T_INTEGER==H5Tget_class(type)) {
- info.ascii = TRUE;
- info.elmt_suf1 = "";
- info.elmt_suf2 = "";
- info.idx_fmt = "(%s)";
- info.line_pre = " %s \"";
- info.line_suf = "\"";
- }
- if (hexdump_g) {
- p_type = H5Tcopy(type);
- } else {
- p_type = h5dump_fixtype(type);
- }
- if (p_type>=0) {
- need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
- buf = malloc(need);
- assert(buf);
- if (H5Aread(attr, p_type, buf)>=0) {
- h5dump_mem(stdout, &info, attr, p_type, space, buf,-1);
- }
- free(buf);
- H5Tclose(p_type);
- }
-
- H5Sclose(space);
- H5Tclose(type);
- H5Aclose(attr);
- } else {
- putchar('\n');
- }
-
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: dataset_list1
- *
- * Purpose: List information about a dataset which should appear on the
- * same line as the dataset name. This information will precede
- * information which is applicable to all objects which will be
- * printed by the caller.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, August 27, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-dataset_list1(hid_t dset)
-{
- hsize_t cur_size[64]; /*current dataset dimensions */
- hsize_t max_size[64]; /*maximum dataset dimensions */
- hid_t space; /*data space */
- int ndims; /*dimensionality */
- int i;
-
- /*
- * Information that goes on the same row as the name. The name has
- * already been printed.
- */
- space = H5Dget_space(dset);
- ndims = H5Sget_simple_extent_dims(space, cur_size, max_size);
- printf (" {");
- for (i=0; i<ndims; i++) {
- HDfprintf (stdout, "%s%Hu", i?", ":"", cur_size[i]);
- if (max_size[i]==H5S_UNLIMITED) {
- HDfprintf (stdout, "/%s", "Inf");
- } else if (max_size[i]!=cur_size[i] || verbose_g>0) {
- HDfprintf(stdout, "/%Hu", max_size[i]);
- }
- }
- if (0==ndims) printf("SCALAR");
- putchar('}');
- H5Sclose (space);
-
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: dataset_list2
- *
- * Purpose: List information about a dataset which should appear after
- * information which is general to all objects.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, August 27, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-dataset_list2(hid_t dset, const char UNUSED *name)
-{
- hid_t dcpl; /*dataset creation property list*/
- hid_t type; /*data type of dataset */
- hid_t space; /*data space of dataset */
- int nf; /*number of filters */
- unsigned filt_flags; /*filter flags */
- H5Z_filter_t filt_id; /*filter identification number */
- unsigned cd_values[20]; /*filter client data values */
- size_t cd_nelmts; /*filter client number of values*/
- size_t cd_num; /*filter client data counter */
- char f_name[256]; /*filter/file name */
- char s[64]; /*temporary string buffer */
- off_t f_offset; /*offset in external file */
- hsize_t f_size; /*bytes used in external file */
- hsize_t total, used; /*total size or offset */
- hsize_t chsize[64]; /*chunk size in elements */
- int ndims; /*dimensionality */
- int n, max_len; /*max extern file name length */
- double utilization; /*percent utilization of storage*/
- int i;
-
- if (verbose_g>0) {
- dcpl = H5Dget_create_plist(dset);
- space = H5Dget_space(dset);
- type = H5Dget_type(dset);
-
- /* Print information about chunked storage */
- if (H5D_CHUNKED==H5Pget_layout(dcpl)) {
- ndims = H5Pget_chunk(dcpl, NELMTS(chsize), chsize/*out*/);
- printf(" %-10s {", "Chunks:");
- total = H5Tget_size(type);
- for (i=0; i<ndims; i++) {
- printf("%s%lu", i?", ":"", (unsigned long)(chsize[i]));
- total *= chsize[i];
- }
- printf("} %lu bytes\n", (unsigned long)total);
- }
-
- /* Print total raw storage size */
- used = H5Sget_simple_extent_npoints(space) * H5Tget_size(type);
- total = H5Dget_storage_size(dset);
- printf(" %-10s ", "Storage:");
- printf("%lu logical byte%s, %lu allocated byte%s",
- (unsigned long)used, 1==used?"":"s",
- (unsigned long)total, 1==total?"":"s");
- if (total>0) {
-#ifdef WIN32
- hsize_t mask = (hsize_t)1 << (8*sizeof(hsize_t)-1);
- if ((used & mask) || (total & mask)) {
- total = 0; /*prevent utilization printing*/
- } else {
- utilization = (hssize_t)used*100.0 /(hssize_t)total;
- }
-#else
- utilization = (used*100.0)/total;
-#endif
- printf(", %1.2f%% utilization", utilization/*(used*100.0)/total*/);
- }
- putchar('\n');
-
- /* Print information about external strorage */
- if ((nf = H5Pget_external_count(dcpl))>0) {
- for (i=0, max_len=0; i<nf; i++) {
- H5Pget_external(dcpl, i, sizeof(f_name), f_name, NULL, NULL);
- n = display_string(NULL, f_name, TRUE);
- max_len = MAX(max_len, n);
- }
- printf(" %-10s %d external file%s\n",
- "Extern:", nf, 1==nf?"":"s");
- printf(" %4s %10s %10s %10s %s\n",
- "ID", "DSet-Addr", "File-Addr", "Bytes", "File");
- printf(" %4s %10s %10s %10s ",
- "----", "----------", "----------", "----------");
- for (i=0; i<max_len; i++) putchar('-');
- putchar('\n');
- for (i=0, total=0; i<nf; i++) {
- if (H5Pget_external(dcpl, i, sizeof(f_name), f_name, &f_offset,
- &f_size)<0) {
- HDfprintf(stdout,
- " #%03d %10Hu %10s %10s ***ERROR*** %s\n",
- i, total, "", "",
- i+1<nf?"Following addresses are incorrect":"");
- } else if (H5S_UNLIMITED==f_size) {
- HDfprintf(stdout, " #%03d %10Hu %10Hu %10s ",
- i, total, (hsize_t)f_offset, "INF");
- display_string(stdout, f_name, TRUE);
- } else {
- HDfprintf(stdout, " #%03d %10Hu %10Hu %10Hu ",
- i, total, (hsize_t)f_offset, f_size);
- display_string(stdout, f_name, TRUE);
- }
- putchar('\n');
- total += f_size;
- }
- printf(" %4s %10s %10s %10s ",
- "----", "----------", "----------", "----------");
- for (i=0; i<max_len; i++) putchar('-');
- putchar('\n');
- }
-
- /* Print information about raw data filters */
- if ((nf = H5Pget_nfilters(dcpl))>0) {
- for (i=0; i<nf; i++) {
- cd_nelmts = NELMTS(cd_values);
- filt_id = H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts,
- cd_values, sizeof(f_name), f_name);
- f_name[sizeof(f_name)-1] = '\0';
- sprintf(s, "Filter-%d:", i);
- printf(" %-10s %s-%u %s {", s,
- f_name[0]?f_name:"method",
- (unsigned)filt_id,
- filt_flags & H5Z_FLAG_OPTIONAL?"OPT":"");
- for (cd_num=0; cd_num<cd_nelmts; cd_num++) {
- printf("%s%u", cd_num?", ":"", cd_values[cd_num]);
- }
- printf("}\n");
- }
- }
-
- /* Print data type */
- printf(" %-10s ", "Type:");
- display_type(type, 15);
- printf("\n");
-
- /* Print address information */
- if (address_g) H5Ddebug(dset, 0);
-
- /* Close stuff */
- H5Tclose(type);
- H5Sclose(space);
- H5Pclose(dcpl);
- }
-
- if (data_g) dump_dataset_values(dset);
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: group_list2
- *
- * Purpose: List information about a group which should appear after
- * information which is general to all objects.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-group_list2(hid_t grp, const char *name)
-{
- iter_t iter;
-
- if (recursive_g) {
- iter.container = name;
- H5Giterate(grp, ".", NULL, list, &iter);
- }
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: datatype_list2
- *
- * Purpose: List information about a data type which should appear after
- * information which is general to all objects.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, November 5, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-datatype_list2(hid_t type, const char UNUSED *name)
-{
- if (verbose_g>0) {
- printf(" %-10s ", "Type:");
- display_type(type, 15);
- printf("\n");
- }
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: link_open
- *
- * Purpose: This gets called to open a symbolic link. Since symbolic
- * links don't correspond to actual objects we simply print the
- * link information and return failure.
- *
- * Return: Success: 0 - an invalid object but successful return
- * of this function.
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, August 27, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-link_open(hid_t location, const char *name)
-{
- char buf[64];
-
- if (H5Gget_linkval (location, name, sizeof(buf), buf)<0) return -1;
- if (NULL==HDmemchr(buf, 0, sizeof(buf))) {
- strcpy(buf+sizeof(buf)-4, "...");
- }
- fputs(buf, stdout);
-
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: list
- *
- * Purpose: Prints the group member name.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Monday, March 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-list (hid_t group, const char *name, void *_iter)
-{
- hid_t obj=-1;
- char buf[512], comment[50], *fullname=NULL, *s=NULL;
- H5G_stat_t sb;
- struct tm *tm;
- herr_t status;
- iter_t *iter = (iter_t*)_iter;
- int n;
-
- /* Print the object name, either full name or base name */
- fullname = fix_name(iter->container, name);
- if (fullname_g) {
- n = display_string(stdout, fullname, TRUE);
- printf("%*s ", MAX(0, 24-n), "");
- } else {
- n = display_string(stdout, name, TRUE);
- printf("%*s ", MAX(0, 24-n), "");
- }
-
- /* Get object information */
- H5E_BEGIN_TRY {
- status = H5Gget_objinfo(group, name, FALSE, &sb);
- } H5E_END_TRY;
- if (status<0) {
- puts("**NOT FOUND**");
- return 0;
- } else if (sb.type<0 || sb.type>=H5G_NTYPES) {
- printf("Unknown type(%d)", sb.type);
- sb.type = -1;
- }
- if (sb.type>=0 && dispatch_g[sb.type].name) {
- fputs(dispatch_g[sb.type].name, stdout);
- }
-
- /*
- * If the object has already been printed then just show the object ID
- * and return.
- */
- if ((s=sym_lookup(&sb))) {
- printf(", same as ");
- display_string(stdout, s, TRUE);
- printf("\n");
- goto done;
- } else {
- sym_insert(&sb, fullname);
- }
-
- /*
- * Open the object. Not all objects can be opened. If this is the case
- * then return right away.
- */
- if (sb.type>=0 &&
- (NULL==dispatch_g[sb.type].open ||
- (obj=(dispatch_g[sb.type].open)(group, name))<0)) {
- printf(" *ERROR*\n");
- goto done;
- }
-
- /*
- * List the first line of information for the object.
- */
- if (sb.type>=0 && dispatch_g[sb.type].list1) {
- (dispatch_g[sb.type].list1)(obj);
- }
- putchar('\n');
-
- /*
- * Show detailed information about the object, beginning with information
- * which is common to all objects.
- */
- if (verbose_g>0 && H5G_LINK!=sb.type) {
- if (sb.type>=0) H5Aiterate(obj, NULL, list_attr, NULL);
- printf(" %-10s %lu:%lu:%lu:%lu\n", "Location:",
- sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
- printf(" %-10s %u\n", "Links:", sb.nlink);
- if (sb.mtime>0 && NULL!=(tm=localtime(&(sb.mtime)))) {
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
- printf(" %-10s %s\n", "Modified:", buf);
- }
- comment[0] = '\0';
- H5Gget_comment(group, name, sizeof(comment), comment);
- strcpy(comment+sizeof(comment)-4, "...");
- if (comment[0]) {
- printf(" %-10s \"", "Comment:");
- display_string(stdout, comment, FALSE);
- puts("\"");
- }
- }
- if (sb.type>=0 && dispatch_g[sb.type].list2) {
- (dispatch_g[sb.type].list2)(obj, fullname);
- }
-
- /*
- * Close the object.
- */
- done:
- if (sb.type>=0 && obj>=0 && dispatch_g[sb.type].close) {
- (dispatch_g[sb.type].close)(obj);
- }
- if (fullname) free(fullname);
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_name
- *
- * Purpose: Returns a malloc'd buffer that contains the PATH and BASE
- * names separated by a single slash. It also removes duplicate
- * and trailing slashes.
- *
- * Return: Success: Ptr to fixed name from malloc()
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-fix_name(const char *path, const char *base)
-{
- size_t n = (path?strlen(path):0) + (base?strlen(base):0) + 3;
- char *s = malloc(n), prev='\0';
- int len=0;
-
- if (path) {
- /* Path, followed by slash */
-#ifdef H5LS_PREPEND_FILENAME
- if ('/'!=*path) s[len++] = '/';
-#endif
- for (/*void*/; *path; path++) {
- if ('/'!=*path || '/'!=prev) prev = s[len++] = *path;
- }
- if ('/'!=prev) prev = s[len++] = '/';
- }
-
- if (base) {
- /* Base name w/o trailing slashes */
- const char *end = base + strlen(base);
- while (end>base && '/'==end[-1]) --end;
- for (/*void*/; base<end; base++) {
- if ('/'!=*base || '/'!=prev) prev = s[len++] = *base;
- }
- }
-
- s[len] = '\0';
- return s;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: get_width
- *
- * Purpose: Figure out how wide the screen is. This is highly
- * unportable, but the user can always override the width we
- * detect by giving a command-line option. These code snippets
- * were borrowed from the GNU less(1).
- *
- * Return: Success: Number of columns.
- *
- * Failure: Some default number of columms.
- *
- * Programmer: Robb Matzke
- * Friday, November 6, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-get_width(void)
-{
- int width = 80; /*the default */
- char *s;
-
- /*
- * Try to get it from the COLUMNS environment variable first since it's
- * value is sometimes wrong.
- */
- if ((s=getenv("COLUMNS")) && *s && isdigit((int)*s)) {
- width = (int)strtol(s, NULL, 0);
- }
-
-#if defined(H5_HAVE_STRUCT_VIDEOCONFIG) && defined(H5_HAVE__GETVIDEOCONFIG)
- {
- /* Microsoft C */
- struct videoconfig w;
- _getvideoconfig(&w);
- width = w.numtextcols;
- }
-#elif defined(H5_HAVE_STRUCT_TEXT_INFO) && defined(H5_HAVE_GETTEXTINFO)
- {
- /* Borland C or DJGPPC */
- struct text_info w;
- gettextinfo(&w);
- width = w.screenwidth;
- }
-#elif defined(H5_HAVE_GETCONSOLESCREENBUFFERINFO)
- {
- /* Win32 C */
- CONSOLE_SCREEN_BUFFER_INFO scr;
- GetConsoleScreenBufferInfo(con_out, &scr);
- width = scr.srWindow.Right - scr.srWindow.Left + 1;
- }
-#elif defined(H5_HAVE__SCRSIZE)
- {
- /* OS/2 */
- int w[2];
- _scrsize(w);
- width = w[0];
- }
-#elif defined(H5_HAVE_TIOCGWINSZ) && defined(H5_HAVE_IOCTL)
-#ifndef __PUMAGON__
-/* the ioctl() call coredump on TFLOPS. Turn it off for now. */
- {
- /* Unix with ioctl(TIOCGWINSZ) */
- struct winsize w;
- if (ioctl(2, TIOCGWINSZ, &w)>=0 && w.ws_col>0) {
- width = w.ws_col;
- }
- }
-#endif
-#elif defined(H5_HAVE_TIOCGETD) && defined(H5_HAVE_IOCTL)
- {
- /* Unix with ioctl(TIOCGETD) */
- struct uwdata w;
- if (ioctl(2, WIOCGETD, &w)>=0 && w.uw_width>0) {
- width = w.uw_width / w.uw_hs;
- }
- }
-#endif
-
- /* Set to at least 1 */
- if (width<1) width = 1;
- return width;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: Opens a file and lists the specified group
- *
- * Return: Success: 0
- *
- * Failure: 1
- *
- * Programmer: Robb Matzke
- * Monday, March 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-main (int argc, char *argv[])
-{
- hid_t file=-1, root=-1;
- char *fname=NULL, *oname=NULL, *x;
- const char *progname="h5ls";
- const char *s = NULL;
- char *rest, *container=NULL;
- int argno;
- H5G_stat_t sb;
- iter_t iter;
- static char root_name[] = "/";
- char drivername[50];
-
- /* Initialize h5tools lib */
- h5tools_init();
-
- /* Build display table */
- DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose,
- dataset_list1, dataset_list2);
- DISPATCH(H5G_GROUP, "Group", H5Gopen, H5Gclose,
- NULL, group_list2);
- DISPATCH(H5G_TYPE, "Type", H5Topen, H5Tclose,
- NULL, datatype_list2);
- DISPATCH(H5G_LINK, "-> ", link_open, NULL,
- NULL, NULL);
-
-#if 0
- /* Name of this program without the path */
- if ((progname=strrchr(argv[0], '/'))) progname++;
- else progname = argv[0];
-#endif
-
- /* Default output width */
- width_g = get_width();
-
- /* Switches come before non-switch arguments */
- for (argno=1; argno<argc && '-'==argv[argno][0]; argno++) {
- if (!strcmp(argv[argno], "--")) {
- /* Last switch */
- argno++;
- break;
- } else if (!strcmp(argv[argno], "--help")) {
- usage(progname);
- exit(0);
- } else if (!strcmp(argv[argno], "--address")) {
- address_g = TRUE;
- } else if (!strcmp(argv[argno], "--data")) {
- data_g = TRUE;
- } else if (!strcmp(argv[argno], "--errors")) {
- show_errors_g = TRUE;
- } else if (!strcmp(argv[argno], "--full")) {
- fullname_g = TRUE;
- } else if (!strcmp(argv[argno], "--group")) {
- grp_literal_g = TRUE;
- } else if (!strcmp(argv[argno], "--label")) {
- label_g = TRUE;
- } else if (!strcmp(argv[argno], "--recursive")) {
- recursive_g = TRUE;
- fullname_g = TRUE;
- } else if (!strcmp(argv[argno], "--simple")) {
- simple_output_g = TRUE;
- } else if (!strcmp(argv[argno], "--string")) {
- string_g = TRUE;
- } else if (!strncmp(argv[argno], "--width=", 8)) {
- width_g = (int)strtol(argv[argno]+8, &rest, 0);
- if (width_g<=0 || *rest) {
- usage(progname);
- exit(1);
- }
- } else if (!strcmp(argv[argno], "--width")) {
- if (argno+1>=argc) {
- usage(progname);
- exit(1);
- } else {
- s = argv[++argno];
- }
- width_g = (int)strtol(s, &rest, 0);
- if (width_g<=0 || *rest) {
- usage(progname);
- exit(1);
- }
- } else if (!strcmp(argv[argno], "--verbose")) {
- verbose_g++;
- } else if (!strcmp(argv[argno], "--version")) {
- print_version(progname);
- exit(0);
- } else if (!strcmp(argv[argno], "--hexdump")) {
- hexdump_g = TRUE;
- } else if (!strncmp(argv[argno], "-w", 2)) {
- if (argv[argno][2]) {
- s = argv[argno]+2;
- } else if (argno+1>=argc) {
- usage(progname);
- exit(1);
- } else {
- s = argv[++argno];
- }
- width_g = (int)strtol(s, &rest, 0);
- if (width_g<=0 || *rest) {
- usage(progname);
- exit(1);
- }
- } else if ('-'!=argv[argno][1]) {
- /* Single-letter switches */
- for (s=argv[argno]+1; *s; s++) {
- switch (*s) {
- case '?':
- case 'h': /* --help */
- usage(progname);
- exit(0);
- case 'a': /* --address */
- address_g = TRUE;
- break;
- case 'd': /* --data */
- data_g = TRUE;
- break;
- case 'e': /* --errors */
- show_errors_g = TRUE;
- break;
- case 'f': /* --full */
- fullname_g = TRUE;
- break;
- case 'g': /* --group */
- grp_literal_g = TRUE;
- break;
- case 'l': /* --label */
- label_g = TRUE;
- break;
- case 'r': /* --recursive */
- recursive_g = TRUE;
- fullname_g = TRUE;
- break;
- case 'S': /* --simple */
- simple_output_g = TRUE;
- break;
- case 's': /* --string */
- string_g = TRUE;
- break;
- case 'v': /* --verbose */
- verbose_g++;
- break;
- case 'V': /* --version */
- print_version(progname);
- exit(0);
- case 'x': /* --hexdump */
- hexdump_g = TRUE;
- break;
- default:
- usage(progname);
- exit(1);
- }
- }
- } else {
- usage(progname);
- exit(1);
- }
- }
-
- /*
- * If no arguments remain then print a usage message (instead of doing
- * absolutely nothing ;-)
- */
- if (argno>=argc) {
- usage(progname);
- exit(1);
- }
-
- /* Turn off HDF5's automatic error printing unless you're debugging h5ls */
- if (!show_errors_g) H5Eset_auto(NULL, NULL);
-
-
- /*
- * Each remaining argument is an hdf5 file followed by an optional slash
- * and object name.
- *
- * Example: ../dir1/foo/bar/baz
- * \_________/\______/
- * file obj
- *
- * The dichotomy is determined by calling H5Fopen() repeatedly until it
- * succeeds. The first call uses the entire name and each subsequent call
- * chops off the last component. If we reach the beginning of the name
- * then there must have been something wrong with the file (perhaps it
- * doesn't exist).
- */
- while (argno<argc) {
- fname = argv[argno++];
- oname = NULL;
- file = -1;
-
- while (fname && *fname) {
- file = h5dump_fopen(fname, drivername, sizeof drivername);
- if (file>=0) {
- if (verbose_g) {
- printf("Opened \"%s\" with %s driver.\n",
- fname, drivername);
- }
- break; /*success*/
- }
-
- /* Shorten the file name; lengthen the object name */
- x = oname;
- oname = strrchr(fname, '/');
- if (x) *x = '/';
- if (!oname) break;
- *oname = '\0';
- }
- if (file<0) {
- fprintf(stderr, "%s: unable to open file\n", argv[argno-1]);
- continue;
- }
- if (oname) oname++;
- if (!oname || !*oname) oname = root_name;
-
- /* Open the object and display it's information */
- if (H5Gget_objinfo(file, oname, TRUE, &sb)>=0 &&
- H5G_GROUP==sb.type && !grp_literal_g) {
- /*
- * Specified name is a group. List the complete contents of the
- * group.
- */
- sym_insert(&sb, oname);
-#ifdef H5LS_PREPEND_FILENAME
- iter.container = container = fix_name(fname, oname);
-#else
- iter.container = container = fix_name("", oname);
-#endif
- H5Giterate(file, oname, NULL, list, &iter);
- free(container);
-
- } else if ((root=H5Gopen(file, "/"))<0) {
- exit(1); /*major problem!*/
-
- } else {
- /*
- * Specified name is a non-group object -- list that object. The
- * container for the object is everything up to the base name.
- */
-#ifdef H5LS_PREPEND_FILENAME
- iter.container = fname;
-#else
- iter.container = "/";
-#endif
- list(root, oname, &iter);
- if (H5Gclose(root)<0) exit(1);
- }
- H5Fclose(file);
- }
- h5tools_close();
-
- return 0;
-}
diff --git a/tools/h5repart.c b/tools/h5repart.c
deleted file mode 100644
index de7b3df..0000000
--- a/tools/h5repart.c
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * Copyright (C) 1998 NCSA
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Wednesday, May 13, 1998
- *
- * Purpose: Repartitions a file family. This program can be used to
- * split a single file into a family of files, join a family of
- * files into a single file, or copy one family to another while
- * changing the size of the family members. It can also be used
- * to copy a single file to a single file with holes.
- */
-
-/* See H5private.h for how to include system headers */
-#include <hdf5.h>
-#ifdef H5_STDC_HEADERS
-# include <ctype.h>
-# include <errno.h>
-# include <fcntl.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <string.h>
-#endif
-
-#ifdef H5_HAVE_UNISTD_H
-# include <sys/types.h>
-# include <unistd.h>
-#endif
-
-#ifdef H5_HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
-#ifdef WIN32
-#include <io.h>
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-#ifndef TRUE
-#define TRUE 1
-#endif
-#define NAMELEN 4096
-#define GB *1024*1024*1024
-
-#ifndef MIN
-#define MIN(X,Y) ((X)<(Y)?(X):(Y))
-#endif
-#ifndef MIN3
-#define MIN3(X,Y,Z) MIN(MIN(X,Y),Z)
-#endif
-
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: Prints a usage message.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Wednesday, May 13, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-usage (const char *progname)
-{
- fprintf(stderr, "usage: %s [-v] [-V] [-[b|m] N[g|m|k]] SRC DST\n",
- progname);
- fprintf(stderr, " -v Produce verbose output\n");
- fprintf(stderr, " -V Print a version number and exit\n");
- fprintf(stderr, " -b N The I/O block size, defaults to 1kB\n");
- fprintf(stderr, " -m N The destination member size or 1GB\n");
- fprintf(stderr, " SRC The name of the source file\n");
- fprintf(stderr, " DST The name of the destination files\n");
- fprintf(stderr, "Sizes may be suffixed with `g' for GB, `m' for MB or "
- "`k' for kB.\n");
- fprintf(stderr, "File family names include an integer printf "
- "format such as `%%d'\n");
- exit (1);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: get_size
- *
- * Purpose: Reads a size option of the form `-XNS' where `X' is any
- * letter, `N' is a multi-character positive decimal number, and
- * `S' is an optional suffix letter in the set [GgMmk]. The
- * option may also be split among two arguments as: `-X NS'.
- * The input value of ARGNO is the argument number for the
- * switch in the ARGV vector and ARGC is the number of entries
- * in that vector.
- *
- * Return: Success: The value N multiplied according to the
- * suffix S. On return ARGNO will be the number
- * of the next argument to process.
- *
- * Failure: Calls usage() which exits with a non-zero
- * status.
- *
- * Programmer: Robb Matzke
- * Wednesday, May 13, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static off_t
-get_size (const char *progname, int *argno, int argc, char *argv[])
-{
- off_t retval=-1;
- char *suffix;
-
- if (isdigit ((int)(argv[*argno][2]))) {
- retval = strtol (argv[*argno]+2, &suffix, 10);
- (*argno)++;
- } else if (argv[*argno][2] || *argno+1>=argc) {
- usage (progname);
- } else {
- retval = strtol (argv[*argno+1], &suffix, 0);
- if (suffix==argv[*argno+1]) usage (progname);
- *argno += 2;
- }
- if (suffix && suffix[0] && !suffix[1]) {
- switch (*suffix) {
- case 'G':
- case 'g':
- retval *= 1024 * 1024 * 1024;
- break;
- case 'M':
- case 'm':
- retval *= 1024 * 1024;
- break;
- case 'k':
- retval *= 1024;
- break;
- default:
- usage (progname);
- }
- } else if (suffix && suffix[0]) {
- usage (progname);
- }
- return retval;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: Split an hdf5 file
- *
- * Return: Success:
- *
- * Failure:
- *
- * Programmer: Robb Matzke
- * Wednesday, May 13, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-main (int argc, char *argv[])
-{
- const char *prog_name; /*program name */
- size_t blk_size=1024; /*size of each I/O block */
- char *buf=NULL; /*I/O block buffer */
- size_t n, i; /*counters */
- ssize_t nio; /*I/O return value */
- int argno=1; /*program argument number */
- int src, dst=-1; /*source & destination files */
- int need_seek=FALSE; /*destination needs to seek? */
- int need_write; /*data needs to be written? */
- struct stat sb; /*temporary file stat buffer */
- int verbose=FALSE; /*display file names? */
- size_t left_overs=0; /*amount of zeros left over */
-
- const char *src_gen_name; /*general source name */
- char src_name[NAMELEN]; /*source member name */
- off_t src_offset=0; /*offset in source member */
- int src_is_family; /*is source name a family name? */
- int src_membno=0; /*source member number */
- off_t src_size; /*source logical member size */
- off_t src_act_size; /*source actual member size */
-
- const char *dst_gen_name; /*general destination name */
- char dst_name[NAMELEN]; /*destination member name */
- off_t dst_offset=0; /*offset in destination member */
- int dst_is_family; /*is dst name a family name? */
- int dst_membno=0; /*destination member number */
- off_t dst_size=1 GB; /*destination logical memb size */
-
- /*
- * Get the program name from argv[0]. Use only the last component.
- */
- if ((prog_name=strrchr (argv[0], '/'))) prog_name++;
- else prog_name = argv[0];
-
- /*
- * Parse switches.
- */
- while (argno<argc && '-'==argv[argno][0]) {
- if (!strcmp (argv[argno], "-v")) {
- verbose = TRUE;
- argno++;
- } else if (!strcmp(argv[argno], "-V")) {
- printf("This is %s version %u.%u release %u\n",
- prog_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE);
- exit(0);
- } else if ('b'==argv[argno][1]) {
- blk_size = get_size (prog_name, &argno, argc, argv);
- } else if ('m'==argv[argno][1]) {
- dst_size = get_size (prog_name, &argno, argc, argv);
- } else {
- usage (prog_name);
- }
- }
-
- /*
- * Get the name for the source file and open the first member. The size
- * of the first member determines the logical size of all the members.
- */
- if (argno>=argc) usage (prog_name);
- src_gen_name = argv[argno++];
- sprintf (src_name, src_gen_name, src_membno);
- src_is_family = strcmp (src_name, src_gen_name);
- if ((src=open (src_name, O_RDONLY))<0) {
- perror (src_name);
- exit (1);
- }
- if (fstat (src, &sb)<0) {
- perror ("fstat");
- exit (1);
- }
- src_size = src_act_size = sb.st_size;
- if (verbose) fprintf (stderr, "< %s\n", src_name);
-
- /*
- * Get the name for the destination file and open the first member.
- */
- if (argno>=argc) usage (prog_name);
- dst_gen_name = argv[argno++];
- sprintf (dst_name, dst_gen_name, dst_membno);
- dst_is_family = strcmp (dst_name, dst_gen_name);
- if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) {
- perror (dst_name);
- exit (1);
- }
- if (verbose) fprintf (stderr, "> %s\n", dst_name);
-
- /* No more arguments */
- if (argno<argc) usage (prog_name);
-
- /* Now the real work, split the file */
- buf = malloc (blk_size);
- while (src_offset<src_size) {
-
- /* Read a block. The amount to read is the minimum of:
- * 1. The I/O block size
- * 2. What's left to write in the destination member
- * 3. Left over zeros or what's left in the source member.
- */
- n = blk_size;
- if (dst_is_family) n = (size_t)MIN((off_t)n, dst_size-dst_offset);
- if (left_overs) {
- n = MIN (n, left_overs);
- left_overs -= n;
- need_write = FALSE;
- } else if (src_offset<src_act_size) {
- n = (size_t)MIN ((off_t)n, src_act_size-src_offset);
- if ((nio=read (src, buf, n))<0) {
- perror ("read");
- exit (1);
- } else if ((size_t)nio!=n) {
- fprintf (stderr, "%s: short read\n", src_name);
- exit (1);
- }
- for (i=0; i<n; i++) {
- if (buf[i]) break;
- }
- need_write = (i<n);
- } else {
- n = 0;
- left_overs = src_size - src_act_size;
- need_write = FALSE;
- }
-
- /*
- * If the block contains non-zero data then write it to the
- * destination, otherwise just remember that we'll have to do a seek
- * later in the destination when we finally get non-zero data.
- */
- if (need_write) {
- if (need_seek && lseek (dst, dst_offset, SEEK_SET)<0) {
- perror ("lseek");
- exit (1);
- }
- if ((nio=write (dst, buf, n))<0) {
- perror ("write");
- exit (1);
- } else if ((size_t)nio!=n) {
- fprintf (stderr, "%s: short write\n", dst_name);
- exit (1);
- }
- need_seek = FALSE;
- } else {
- need_seek = TRUE;
- }
-
- /*
- * Update the source offset and open the next source family member if
- * necessary. The source stream ends at the first member which
- * cannot be opened because it doesn't exist. At the end of the
- * source stream, update the destination offset and break out of the
- * loop. The destination offset must be updated so we can fix
- * trailing holes.
- */
- src_offset += n;
- if (src_offset==src_act_size) {
- close (src);
- if (!src_is_family) {
- dst_offset += n;
- break;
- }
- sprintf (src_name, src_gen_name, ++src_membno);
- if ((src=open (src_name, O_RDONLY))<0 && ENOENT==errno) {
- dst_offset += n;
- break;
- } else if (src<0) {
- perror (src_name);
- exit (1);
- }
- if (fstat (src, &sb)<0) {
- perror ("fstat");
- exit (1);
- }
- src_act_size = sb.st_size;
- if (src_act_size>src_size) {
- fprintf (stderr, "%s: member truncated to %lu bytes\n",
- src_name, (unsigned long)src_size);
- }
- src_offset = 0;
- if (verbose) fprintf (stderr, "< %s\n", src_name);
- }
-
- /*
- * Update the destination offset, opening a new member if one will be
- * needed. The first member is extended to the logical member size
- * but other members might be smaller if they end with a hole.
- */
- dst_offset += n;
- if (dst_is_family && dst_offset==dst_size) {
- if (0==dst_membno) {
- if (lseek (dst, dst_size-1, SEEK_SET)<0) {
- perror ("lseek");
- exit (1);
- }
- if (read (dst, buf, 1)<0) {
- perror ("read");
- exit (1);
- }
- if (lseek (dst, dst_size-1, SEEK_SET)<0) {
- perror ("lseek");
- exit (1);
- }
- if (write (dst, buf, 1)<0) {
- perror ("write");
- exit (1);
- }
- }
- close (dst);
- sprintf (dst_name, dst_gen_name, ++dst_membno);
- if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) {
- perror (dst_name);
- exit (1);
- }
- dst_offset = 0;
- need_seek = FALSE;
- if (verbose) fprintf (stderr, "> %s\n", dst_name);
- }
- }
-
- /*
- * Make sure the last family member is the right size and then close it.
- * The last member can't end with a hole or hdf5 will think that the
- * family has been truncated.
- */
- if (need_seek) {
- if (lseek (dst, dst_offset-1, SEEK_SET)<0) {
- perror ("lseek");
- exit (1);
- }
- if (read (dst, buf, 1)<0) {
- perror ("read");
- exit (1);
- }
- if (lseek (dst, dst_offset-1, SEEK_SET)<0) {
- perror ("lseek");
- exit (1);
- }
- if (write (dst, buf, 1)<0) {
- perror ("write");
- exit (1);
- }
- }
- close (dst);
-
- /* Free resources and return */
- free (buf);
- return 0;
-}
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
deleted file mode 100644
index 30b381c..0000000
--- a/tools/h5toh4.c
+++ /dev/null
@@ -1,2592 +0,0 @@
-/******************************************************************************
-
- Description: This file contains routines to translate H5 files to H4 files.
-
- Author: Paul Harten for the University of Illinois, NCSA
-
- Creation Date: 04 October 1998
-
- History:
-
-
-*****************************************************************************/
-
-#include "h5toh4.h"
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <h5tools.h>
-
-
-#ifdef WIN32
-typedef unsigned int mode_t;
-#endif
-
-#ifndef S_ISDIR
-#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR)
-#endif
-extern void PrintOptions_h5toh4(void);
-extern char *BuildFilename(char *h5_filename, char *h4_extension);
-extern int test_file(char *filename, int oflag, mode_t mode);
-extern int test_dir(char *);
-extern int h5toh4(char *, char *);
-
-extern herr_t convert_group(hid_t, char *, op_data_t *);
-extern herr_t convert_dataset(hid_t, char *, op_data_t *);
-extern herr_t convert_all(hid_t, char *, op_data_t *);
-extern herr_t convert_attr(hid_t, char *, op_data_t *);
-extern herr_t convert_shared_dataset(hid_t, int, op_data_t *);
-extern herr_t convert_shared_group(hid_t, int, op_data_t *);
-extern herr_t convert_dataset_string(hid_t, char *, op_data_t *);
-extern int32 h5type_to_h4type(hid_t);
-extern hid_t h4type_to_memtype(int32);
-
-extern void free_table(table_t **temp);
-extern void dump_tables(char* name, table_t* table);
-extern int get_table_idx(table_t*, unsigned long *);
-extern int get_tableflag(table_t*, int);
-extern int set_tableflag(table_t*, int);
-extern char* get_objectname(table_t*, int);
-
-typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
-
-static int prefix_len = 1024;
-static char *prefix;
-static table_t *group_table, *dset_table, *type_table;
-
-static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type);
-
-
-/*****************************************************************************
-
- Routine: main()
-
- Description: This routine check out arguments sent, makes sure everything is
- ok, chooses between the acceptable argument formats and then
- calls h5toh4().
-
- Input: arg - the number of arguments from the call + 1;
- argv - a pointer to an array of strings which are the arguments.
- This includes the routine name as the first string.
-
- Output: function return - error status
-
-*****************************************************************************/
-
-int
-main(int argc, char *argv[])
-{
- char *h5_filename=NULL;
- char *h4_filename=NULL;
- char *h4_extension;
- int status = 0;
- int status2 = 0;
-
-
- argc--;
- argv++;
-
- if (argc == 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h5toh4();
- return -1;
- }
-
- /* take care -h (help) option first */
- { int i;
- for (i=0; i < argc; i++)
- if ( HDstrcmp(argv[i],"-h") == 0 ) {
- PrintOptions_h5toh4();
- return 0;
- }
- }
-
- /*fargv = argv; */
-
- /* Change -m with 1 filename to as 1 filename case */
- if (argc == 2 && HDstrcmp(argv[0],"-m") == 0) {
- argv++;
- argc--;
- }
-
- switch(argc) {
-
- case 0:
-
- PrintOptions_h5toh4();
- break;
-
- case 1: /* h5toh4 file1 */
- h5_filename = argv[0];
-
- if (HDstrcmp(h5_filename,"-m") == 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h5toh4();
- status = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h5_filename,O_EXCL,(mode_t)(S_IRUSR|S_IRGRP|S_IROTH)) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
- if (test_dir(h5_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
-#endif
- h4_extension = HDstrdup("hdf");
-
- h4_filename = BuildFilename(h5_filename,h4_extension);
- if (h4_filename == NULL) {
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h4_filename,O_CREAT|O_EXCL,(mode_t)(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
-#endif
- status = h5toh4(h5_filename, h4_filename);
- if ( status != 0 ) {
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- }
- if (h4_filename != NULL) {
- HDfree(h4_filename);
- }
-
- break;
-
- case 2: /* h5toh4 file_in file_out */
- h5_filename = argv[0];
- h4_filename = argv[1];
-
- if (HDstrcmp(h4_filename,"-m") == 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h5toh4();
- status = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h5_filename,O_EXCL,292) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
- if (test_dir(h5_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
- if (test_file(h4_filename,O_CREAT|O_RDWR,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
- if (test_dir(h4_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h4_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status = -1;
- break;
- }
-#endif
- status = h5toh4(h5_filename, h4_filename);
- if ( status != 0 ) {
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- }
- break;
-
- default: /* h5toh4 -m file1 file2 file3 ... */
- if (HDstrcmp(argv[0],"-m") != 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h5toh4();
- status = -1;
- break;
- }
- argv++;
- argc--;
-
- while ( argc > 0 ) {
- h5_filename = argv[0];
- argv++;
- argc--;
-
- if (HDstrcmp(h5_filename,"-m") == 0) {
- fprintf(stderr,"\nError: Invalid Arguments\n");
- PrintOptions_h5toh4();
- status2 = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h5_filename,O_EXCL,292) != 0 ) { /* 292 Decimal - 0444 Octal, a+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status2 = -1;
- continue;
- }
- if (test_dir(h5_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status2 = -1;
- continue;
- }
-#endif
- h4_extension = HDstrdup("hdf");
-
- h4_filename = BuildFilename(h5_filename,h4_extension);
- if (h4_filename == NULL) {
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status2 = -1;
- continue;
- }
-#ifndef WIN32
- if (test_file(h4_filename,O_CREAT|O_EXCL,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status2 = -1;
- continue;
- }
-#endif
- status = h5toh4(h5_filename, h4_filename);
- if ( status != 0 ) {
- fprintf(stderr,"Error: Problem with %s\n",h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
- status2 = status;
- }
- if (h4_filename != NULL) {
- HDfree(h4_filename);
- }
-
- }
- status = status2;
- break;
- }
-
- return status;
-
-}
-
-
-/*****************************************************************************
-
- Routine: PrintOptions_h5toh4()
-
- Description: This routine prints the acceptable argument formats out to stderr.
-
- Input: None
-
- Output: output to stderr
-
-*****************************************************************************/
-
-void PrintOptions_h5toh4(void)
-{
- fprintf(stderr,"\nh5toh4 -h (gives this print-out)\n");
- fprintf(stderr,"h5toh4 file.h5 file.hdf\n");
- fprintf(stderr,"h5toh4 file.h5\n");
- fprintf(stderr,"h5toh4 -m file1.h5 file2.h5 ...\n\n");
-}
-
-
-/*****************************************************************************
-
- Routine: h5toh4()
-
- Description: This routine translates information from a HDF5 file into a
- HDF4 file.
-
- Input: h5_filename - filename of HDF5 file,
- h4_filename - filename of HDF4 file
-
- Output: function return - error status
-
-*****************************************************************************/
-
-int h5toh4(char *h5_filename, char *h4_filename)
-{
-
- hid_t fid, gid;
- hid_t plist=H5P_DEFAULT;
- int status = 0;
- int32 hfile_id;
- int32 sd_id;
- op_data_t op_data;
- void *edata;
- hid_t (*func)(void*);
-
-
- find_objs_t *info = malloc(sizeof(find_objs_t));
-
-
-
- /* open hdf5 file */
- if ((fid = H5Fopen (h5_filename, H5F_ACC_RDONLY, plist)) <= 0) {
- fprintf(stderr,"Error: Unable to open file %s\n",h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- return (fid);
- }
-
- /* open root group */
- if ((gid = H5Gopen (fid, "/")) <= 0 ) {
- fprintf(stderr,"Error: Unable to open root group\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- return (gid);
- } else {
-
- /* open hdf4 file */
- if ((hfile_id = Hopen(h4_filename, DFACC_CREATE, 0)) <= 0) {
- fprintf(stderr,"Error: Unable to open file %s\n", h4_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- return (hfile_id);
- } else {
-
- if ((sd_id = SDstart(h4_filename, DFACC_RDWR)) <= 0) {
- fprintf(stderr,"Error: Unable to open file %s, using SDstart\n", h4_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- return (sd_id);
- } else {
-
- /* Initialize Vgroup interface */
- if ((status = Vstart(hfile_id)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to initialize Vgroup interface\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
- /* allocate and initialize internal data structure */
- init_table(&group_table);
- init_table(&type_table);
- init_table(&dset_table);
- init_prefix(&prefix, prefix_len);
-
- /* init the find_objs_t*/
- info->threshold = 0;
- info->prefix_len = prefix_len;
- info->prefix = prefix;
- info->group_table = group_table;
- info->type_table = type_table;
- info->dset_table = dset_table;
- info->status = status;
-
-
-
- /* Disable error reporting */
- H5Eget_auto (&func, &edata);
- H5Eset_auto (NULL, NULL);
-
- /* find all objects one time */
- if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)find_objs, (void*)info)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- }
-
- /* Enable error reporting */
- H5Eset_auto (func, edata);
-
-#ifdef H5DUMP_DEBUG
- dump_tables();
-#endif
-
- if (status != SUCCEED) {
- fprintf(stderr,"Error: internal error! \n");
- goto done;
- }
-
- op_data.hfile_id = hfile_id;
- op_data.sd_id = sd_id;
- op_data.vgroup_id = 0;
-
- /* start at root group */
- if (( status = convert_group (gid, HDstrdup("/"), &op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_group did not work for %s\n","/");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
- /* Terminate access to Vgroup interface */
- if ((status = Vend(hfile_id)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to terminate Vgroup interface\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
- }
-
- /* close hdf4 SDS */
- if ((status = SDend(sd_id)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close file %s, from SDstart\n", h4_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
- }
-
- /* close hdf4 file */
- if ((status = Hclose(hfile_id)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close file %s\n", h4_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
- }
-
- if ((status = H5Gclose (gid)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close root group\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
- if ((status = H5Fclose (fid)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close file %s\n", h5_filename);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
- status = FAIL;
- }
-
-done:
- free_table(&group_table);
- free_table(&dset_table);
- free_table(&type_table);
-
- return status;
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: convert_group
- *
- * Purpose: Dump everything within the specified group
- *
- * Return: status
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_group (hid_t gid, char *name, op_data_t *op_data) {
-H5G_stat_t statbuf;
-
- int32 hfile_id;
- int32 vgroup_id;
- int32 obj_idx;
- int32 status;
- int idx, flag;
-
- hfile_id = op_data->hfile_id;
-
- if ((vgroup_id = Vattach(hfile_id, -1, "w")) <= 0 ) {
- fprintf(stderr,"Error: Unable to create new vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(vgroup_id);
- }
-
- if ((status = Vsetname(vgroup_id, name)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to set name on new vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- if ((status = Vsetclass(vgroup_id, "HDF5")) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to set class on new vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- if (op_data->vgroup_id == 0) {
- obj_idx = -1; /* Indexes assigned below start from 0 */
- } else {
- if ((obj_idx = Vinsert(op_data->vgroup_id, vgroup_id)) < 0) {
- fprintf(stderr,"Error: Index %d of the new vgroup is illegal\n",(int)obj_idx);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(obj_idx);
- }
- }
- op_data->vgroup_id = vgroup_id;
- op_data->sds_id = 0;
- op_data->vdata_id = 0;
- op_data->obj_idx = obj_idx;
-
-
- /* hard link */
- if ((status = H5Gget_objinfo(gid, ".", TRUE, &statbuf)) != SUCCEED ) {
- fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return (status);
- }
-
- if (HDstrcmp(name,"/") == 0) { /* this is the root group, just iterate */
-
- if ((status = H5Aiterate(gid, NULL, (H5A_operator_t)convert_attr, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the attributes\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- } else {
-
- if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
-
- fprintf(stderr,"Error: object not found, %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- status = FAIL;
-
- } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
-
- fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- status = FAIL;
-
- } else if(flag == TRUE ) { /* this has already been converted, don't convert the attributes again */
-
- if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- } else { /* flag == FALSE */
-
- /* this is now being converted */
- if ((status = set_tableflag(group_table,idx)) < 0 ) {
- fprintf(stderr,"Error: set_tableflag should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- if ((status = H5Aiterate(gid, NULL, (H5A_operator_t)convert_attr, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the attributes\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- if ((status = H5Giterate(gid, ".", NULL, (H5G_operator_t)convert_all, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- return(status);
- }
-
- }
-
- }
-
-
- if ((status = Vdetach(vgroup_id)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to detach the new Vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
- status = FAIL;
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_dataset
- *
- * Purpose: Convert the specified data set
- *
- * Return: status
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_dataset (hid_t did, char *name, op_data_t *op_data) {
-hid_t type, space, class, mem_type, type2;
-/* H5G_stat_t statbuf; */
-size_t typesize;
-int i, idx;
-int32 dim_sizes[32], start[32], edges[32];
-int ndims;
-int ndimf;
-hsize_t dims[32], maxdims[32];
-hsize_t dimf[4];
-int permf[4];
-int32 hfile_id;
-int32 sd_id;
-int32 sds_id;
-int32 vdata_id;
-int32 vgroup_id;
-int32 n_values;
-int32 status;
-int32 h4_type;
-int32 recsize;
-int32 n_records, num_of_recs, record_pos;
-intn nmembers;
-char *buffer=NULL; /* read/write buffer*/
-char fieldname_list[4096] = "\0";
-char *fieldname=NULL;
-hid_t fieldtype;
-int32 order;
-off_t offset;
-off_t offset_array[512];
-hid_t h4type_array[512], memtype_array[512];
-int32 order_array[512];
-
-
- /* hard link */
-/*
- if ((status = H5Gget_objinfo(did, ".", TRUE, &statbuf)) != SUCCEED ) {
- fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return (status);
- }
-*/
-
- if ((type = H5Dget_type(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((space = H5Dget_space(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
- fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((ndims = H5Sget_simple_extent_dims(space,dims,maxdims)) < 0 ) {
- fprintf(stderr, "Error: Problems getting ndims, dims, and maxdims of dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = ndims;
- return status;
- }
-
- if ((class = H5Tget_class(type)) < 0 ) {
- fprintf(stderr,"Error: problem with getting class\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = class;
- return status;
- }
-
- switch (class) {
- case H5T_INTEGER:
- case H5T_FLOAT:
- sd_id = op_data->sd_id;
-#define NEWWAY
-#ifdef NEWWAY
- if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-#else
- if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- if ((typesize = H5Tget_size(mem_type)) <= 0) {
- fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-#endif
- if ((buffer = HDmalloc(n_values*typesize)) == NULL) {
- fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((status = H5Dread(did, mem_type, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
- fprintf(stderr, "Error: Problems with H5Dread\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- for (i=0;i<ndims;i++) {
- if (maxdims[i] == H5S_UNLIMITED) {
- if ( i == 0 ) {
- dim_sizes[0] = 0; /* this is how HDF4 communicates unlimited dimension */
- } else {
- dim_sizes[i] = (int32)dims[i];
- }
- } else {
- dim_sizes[i] = (int32)maxdims[i];
- }
- start[i] = 0;
- edges[i] = (int32)dims[i];
- }
- if ((sds_id = SDcreate(sd_id, name, h4_type, ndims, dim_sizes)) <= 0 ) {
- fprintf(stderr, "Error: Unable to create SDS %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- op_data->sds_id = sds_id;
- if ((status = SDwritedata(sds_id, start, NULL, edges, buffer)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to write SDS %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
- if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
- fprintf(stderr,"Error: iterate over attributes\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
- if ((status = SDendaccess(sds_id)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to end access to SDS %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
- break;
- case H5T_TIME:
- fprintf(stderr,"Warning: H5T_TIME not yet implemented.\n");
- break;
- case H5T_STRING:
- if (ndims==1) {
- convert_dataset_string(did, name, op_data);
- } else {
- fprintf(stderr,"Warning: HDF5 datasets of H5T_STRING type with ndims > 1 are not converted.\n");
- }
- break;
- case H5T_BITFIELD:
- fprintf(stderr,"Warning: H5T_BITFIELD not yet implemented.\n");
- break;
- case H5T_OPAQUE:
- fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
- break;
- case H5T_ARRAY:
- fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
- break;
- case H5T_COMPOUND:
- if (ndims==1) {
- if ((nmembers = H5Tget_nmembers(type)) <= 0 ) {
- fprintf(stderr, "Error: Unable to get information about compound datatype %d\n",nmembers);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
-
- offset = 0;
- for (idx=0;idx<nmembers;idx++) {
- if ((fieldtype = H5Tget_member_type(type, idx)) < 0 ) {
- fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",fieldtype,idx);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- /* Special case for array fields */
- if(H5Tget_class(fieldtype)==H5T_ARRAY) {
- hid_t arr_base_type;
-
- /* Get the number of dimensions */
- if ((ndimf = H5Tget_array_ndims(fieldtype)) < 0 || ndimf > H5S_MAX_RANK ) {
- fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- /* Get the dimensions and dimension permutations */
- if (H5Tget_array_dims(fieldtype,dimf,permf) < 0) {
- fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- /* Get the 'real' field type */
- if ((arr_base_type=H5Tget_super(fieldtype)) < 0) {
- fprintf(stderr, "Error: cannot retrieve base type for array\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- if (H5Tclose(fieldtype) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
-
- /* Assign the array's base type as the field type for future use */
- fieldtype=arr_base_type;
- } /* end if */
- else
- ndimf=0;
-#ifdef NEWWAY
- if (FAIL==h5atomic_type_to_h4type(fieldtype, &mem_type, &typesize, &h4_type)){
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-#else
- if ((h4_type = h5type_to_h4type(fieldtype)) < 0 ) {
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- if ((typesize = H5Tget_size(mem_type)) <= 0) {
- fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-#endif
- order = 1;
- if (ndimf > 0) {
- order *= dimf[permf[0]];
- if (ndimf > 1) {
- order *= dimf[permf[1]];
- if (ndimf > 2) {
- order *= dimf[permf[2]];
- if (ndimf > 3) {
- order *= dimf[permf[3]];
- }
- }
- }
- }
- h4type_array[idx] = h4_type; /* used for VSfdefine */
- memtype_array[idx] = mem_type; /* used during the build of the memory compound type */
- offset_array[idx] = offset; /* used during the build of the memory compound type */
- order_array[idx] = order; /* used for VSfdefine */
-
- offset += order * typesize; /* calculating packed size of memory compound type */
- }
- hfile_id = op_data->hfile_id;
- vgroup_id = op_data->vgroup_id;
- if ((vdata_id = VSattach(hfile_id, -1, "w")) <= 0 ) {
- fprintf(stderr, "Error: Unable to create vdata %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-/*
- * This step is done during the convert_shared_dataset() call instead of here.
- *
- if ((idx = Vinsert(vgroup_id, vdata_id)) < 0 ) {
- fprintf(stderr, "Error: Unable to insert vdata %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-*/
- op_data->vdata_id = vdata_id;
- if ((status = VSsetname(vdata_id, name)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set vdata name %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((status = VSsetclass(vdata_id, "HDF5")) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set class on vdata %s\n", name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((type2 = H5Tcreate(H5T_COMPOUND, (size_t)offset)) <= 0 ) {
- fprintf(stderr, "Error: unable to execute H5Tcreate()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- for (idx=0;idx<nmembers;idx++) {
- /* Special case for array fields */
- if(H5Tget_member_class(type,idx)==H5T_ARRAY) {
- hid_t arr_type;
-
- if ((arr_type = H5Tget_member_type(type, idx)) < 0 ) {
- fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",arr_type,idx);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- /* Get the number of dimensions */
- if ((ndimf = H5Tget_array_ndims(arr_type)) < 0 || ndimf > H5S_MAX_RANK ) {
- fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- /* Get the dimensions and dimension permutations */
- if (H5Tget_array_dims(arr_type,dimf,permf) < 0) {
- fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- if (H5Tclose(arr_type) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- } /* end if */
- else
- ndimf=0;
-
- if ((fieldname = H5Tget_member_name(type, idx)) == NULL ) {
- fprintf(stderr, "Error: Unable to get fieldname for compound type %d, idx %d\n", type, idx);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((offset = H5Tget_offset(memtype_array[idx])) < 0 || offset >= 128 ) {
- fprintf(stderr, "Error: H5Tget_offset() is returning a bad value %d\n",(int)offset);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- if (ndimf == 0 ) {
- if ((status = H5Tinsert(type2,fieldname,offset_array[idx]+offset,memtype_array[idx])) != SUCCEED ) {
- fprintf(stderr, "Error: Problems inserting field into compound datatype\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- } else {
- hid_t arr_type;
-
- /* Create the array datatype */
- if ((arr_type = H5Tarray_create(memtype_array[idx], ndimf, dimf, permf)) < 0 ) {
- fprintf(stderr,"Error: cannot create array datatype\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
-
- if ((status = H5Tinsert(type2,fieldname,offset_array[idx]+offset,arr_type)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems inserting field into compound datatype\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
-
- if (H5Tclose(arr_type) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
- }
- if ((status = VSfdefine(vdata_id, fieldname, h4type_array[idx], order_array[idx])) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set field %d\n", idx);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- strcat(fieldname_list,fieldname);
- if (idx<nmembers-1) {
- strcat(fieldname_list,", ");
- }
-
- if (fieldname != NULL) {
- HDfree(fieldname);
- }
- }
- if ((status = VSsetfields(vdata_id, fieldname_list)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set fieldname list %s\n", name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((status = VSsetinterlace(vdata_id, FULL_INTERLACE)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set FULL_INTERLACE mode, status %d\n", (int)status);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((recsize = H5Tget_size(type2)) <= 0 ) {
- fprintf(stderr, "Error: Unable to get record size %d\n", (int)recsize);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
-/*
- Since the space is rank 1, n_records does not depend on maxdims.
-*/
- n_records = n_values;
- if ((buffer = HDmalloc(n_records*recsize)) == NULL) {
- fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((status = H5Dread(did, type2, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
- fprintf(stderr, "Error: Problems with H5Dread\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((status = H5Tclose(type2)) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- if ((record_pos = VSseek(vdata_id, 0)) != 0 ) {
- fprintf(stderr, "Error: Could not seek the beginning of the Vdata, %d\n", (int)record_pos);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = record_pos;
- break;
- }
- if ((num_of_recs = VSwrite(vdata_id, (void *)buffer, n_records, FULL_INTERLACE)) != n_records ) {
- fprintf(stderr, "Error: Only able to write %d of %d records\n", (int)num_of_recs, (int)n_records);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = num_of_recs;
- break;
- }
-
- /* there are only vdata attributes, no field attributes */
- if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
- fprintf(stderr,"Error: iterate over attributes\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
- if ((status = VSdetach(vdata_id)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to detach to vdata %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- break;
- }
-
- } else {
-
- fprintf(stderr,"Warning: HDF5 datasets of H5T_COMPOUND type with ndims > 1 are not converted.\n");
-
- }
- break;
- default:
- fprintf(stderr,"Error: %d class not found\n",class);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
-
- if ((status = H5Tclose(type)) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
-
- if ((status = H5Sclose(space)) < 0 ) {
- fprintf(stderr,"Error: closing space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- }
-
- if (buffer != NULL) {
- HDfree(buffer);
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_attr
- *
- * Purpose: dump the attribute
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-
-herr_t
-convert_attr (hid_t attr, char *attr_name, op_data_t *op_data)
-{
-hid_t attr_id, type, space, mem_type, class;
-size_t typesize;
-char *attr_values=NULL;
-int32 status;
-int32 h4_type;
-int32 sds_id;
-int32 vdata_id;
-int32 vgroup_id;
-int32 n_values;
-int32 order;
-hid_t fxdlenstr;
-size_t lenstr;
-H5T_cset_t cset;
-H5T_str_t strpad;
-
- sds_id = op_data->sds_id;
- vdata_id = op_data->vdata_id;
- vgroup_id = op_data->vgroup_id;
-
- if ((attr_id = H5Aopen_name (attr, attr_name))>= 0) {
-
- if ((type = H5Aget_type(attr_id)) <= 0) {
- fprintf(stderr, "Error: H5Aget_type() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((class = H5Tget_class(type)) < 0 ) {
- fprintf(stderr,"Error: problem with getting class\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = class;
- return status;
- }
-
- switch (class) {
- case H5T_INTEGER:
- case H5T_FLOAT:
-
-
- if ((space = H5Aget_space(attr_id)) <= 0) {
- fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
- fprintf(stderr, "Error: H5sget_simple_extent_npoints() didn't return correct value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
-#ifdef NEWWAY
- if (FAIL==h5atomic_type_to_h4type(type, &mem_type, &typesize, &h4_type)){
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-#else
- if ((h4_type = h5type_to_h4type(type)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((mem_type = h4type_to_memtype(h4_type)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((typesize = H5Tget_size(mem_type)) <= 0) {
- fprintf(stderr, "Error: H5Tget_size() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-#endif
-
- if ((attr_values = HDmalloc(n_values*typesize)) == NULL) {
- fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((status = H5Aread(attr_id, mem_type, attr_values)) != SUCCEED) {
- fprintf(stderr, "Error: Problems with H5Aread\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if (sds_id != 0) {
- if ((status = SDsetattr(sds_id, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- } else if (vdata_id != 0) {
- if ((status = VSsetattr(vdata_id, -1, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- } else {
- if ((status = Vsetattr(vgroup_id, attr_name, h4_type, n_values, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- }
-
- if ((status = H5Sclose(space)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems closing H5Sclose\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- if ((status = H5Aclose(attr_id)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems closing H5Aclose\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if (attr_values != NULL) {
- HDfree(attr_values);
- }
-
- status = SUCCEED;
- break;
-
- case H5T_TIME:
- fprintf(stderr,"Warning: H5T_TIME attribute not yet implemented.\n");
- break;
- case H5T_STRING:
-
- fxdlenstr = type;
- h4_type = DFNT_CHAR;
-
- if ((space = H5Aget_space(attr_id)) <= 0) {
- fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
- fprintf(stderr, "Error: H5sget_simple_extent_npoints() didn't return correct value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((mem_type = H5Tcopy(H5T_C_S1)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = mem_type;
- return status;
- }
- if ((lenstr = H5Tget_size(fxdlenstr)) <= 0 ) {
- fprintf(stderr, "Error: size of fixed length string type should not be %d\n",(int)lenstr);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return lenstr;
- }
- if ((status = H5Tset_size(mem_type,lenstr)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_size()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return status;
- }
-
- strpad = H5Tget_strpad(fxdlenstr);
- if ((strpad != H5T_STR_NULLTERM) && (strpad != H5T_STR_NULLPAD) && (strpad != H5T_STR_SPACEPAD)) {
- fprintf(stderr, "Error: Invalid string padding value, %d\n",(int)strpad);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return strpad;
- }
- if ((status = H5Tset_strpad(mem_type, H5T_STR_SPACEPAD)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_strpad()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return status;
- }
-
- if ((cset = H5Tget_cset(fxdlenstr)) != H5T_CSET_ASCII ) {
- fprintf(stderr, "Error: cset value != %d\n",(int)H5T_CSET_ASCII);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return cset;
- }
- if ((status = H5Tset_cset(mem_type,cset)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_cset()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- return status;
- }
-
- order = n_values * lenstr;
- if ((attr_values = HDmalloc(order)) == NULL) {
- fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((status = H5Aread(attr_id, mem_type, attr_values)) != SUCCEED) {
- fprintf(stderr, "Error: Problems with H5Aread\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if (sds_id != 0) {
- if ((status = SDsetattr(sds_id, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- } else if (vdata_id != 0) {
- if ((status = VSsetattr(vdata_id, -1, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- } else {
- if ((status = Vsetattr(vgroup_id, attr_name, h4_type, order, attr_values)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set %s attribute.\n",attr_name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- }
-
- if ((status = H5Sclose(space)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems closing H5Sclose\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- if ((status = H5Aclose(attr_id)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems closing H5Aclose\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if (attr_values != NULL) {
- HDfree(attr_values);
- }
-
- status = SUCCEED;
- break;
- case H5T_BITFIELD:
- fprintf(stderr,"Warning: H5T_BITFIELD attribute not yet implemented.\n");
- break;
- case H5T_OPAQUE:
- fprintf(stderr,"Warning: H5T_OPAQUE attribute not yet implemented.\n");
- break;
- case H5T_COMPOUND:
- fprintf(stderr,"Warning: H5T_COMPOUND attribute not implemented.\n");
- break;
- default:
- fprintf(stderr,"Error: %d class not found\n",class);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- }
-
- if ((status = H5Tclose(type)) != SUCCEED ) {
- fprintf(stderr, "Error: Problems closing H5Tclose\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_attr", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- } else {
-
- status = FAIL;
-
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_all
- *
- * Purpose: Dump everything in the specified object
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_all (hid_t group, char *name, op_data_t *op_data)
-{
- hid_t obj;
- H5G_stat_t statbuf, statbuf2;
- int status;
- op_data_t op_data_save;
- int32 vgroup_id;
- int32 sd_id;
- int32 sds_id;
- int idx, flag;
- void *edata;
- hid_t (*func)(void*);
-
- op_data_save = *op_data;
-
- vgroup_id = op_data->vgroup_id;
- sd_id = op_data->sd_id;
- sds_id = op_data->sds_id;
-
- if ((status = H5Gget_objinfo(group, name, FALSE, &statbuf)) != SUCCEED ) {
- fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (status);
- }
- statbuf2 = statbuf;
-
- switch (statbuf.type) {
-
- case H5G_LINK: /* this is a soft link only */
-
-
- /* Disable error reporting */
- H5Eget_auto (&func, &edata);
- H5Eset_auto (NULL, NULL);
-
- /* test to see if object exists */
- if ((status = H5Gget_objinfo(group, name, TRUE, NULL)) != SUCCEED ) {
- fprintf(stderr,"Warning: the object pointed to by the symbolic link \"%s\" does not exist.\n",name);
- }
-
- /* Enable error reporting */
- H5Eset_auto (func, edata);
-
- if (status != SUCCEED) {
- break;
- }
-
- /* follow link for type */
- if ((status = H5Gget_objinfo(group, name, TRUE, &statbuf)) != SUCCEED ) {
- fprintf(stderr,"Error: H5Gget_objinfo() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (status);
- }
-
- if (statbuf.type==H5G_DATASET ) {
-
- if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
-
- fprintf(stderr,"Error: object not found\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
-
- fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if(flag == TRUE ) { /* this has already been converted, add as a tag/ref */
-
- if ((obj = H5Dopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open H5 dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to convert to tag/ref\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- }
- }
- if ((status = H5Dclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- } else { /* flag == FALSE */
-
- if ((obj = H5Dopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open H5 dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if (( status = convert_dataset (obj, name, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_dataset did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to convert to tag/ref\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- }
- if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
- fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- break;
- }
- }
- if ((status = H5Dclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- }
-
- } else if (statbuf.type==H5G_GROUP ) {
-
- if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
-
- fprintf(stderr,"Error: object not found\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
-
- fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if(flag == TRUE ) {
-
- if (( status = convert_shared_group (group, idx, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_group did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- } else { /* flag == FALSE */
-
- if ((obj = H5Gopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open group\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if (( status = convert_group (obj, name, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_group did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- }
- if ((status = H5Gclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close group %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- }
-
- }
-
- break;
-
- case H5G_GROUP:
-
- if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
-
- fprintf(stderr,"Error: object not found\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
-
- fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if(flag == TRUE ) {
-
- if (( status = convert_shared_group (group, idx, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_group did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- } else { /* flag == FALSE */
-
- if ((obj = H5Gopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open group\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if (( status = convert_group (obj, name, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_group did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- }
- if ((status = H5Gclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close group %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- }
-
- break;
-
- case H5G_DATASET:
-
- if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
-
- fprintf(stderr,"Error: object not found\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
-
- fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
-
- } else if(flag == TRUE ) { /* this has already been converted, add as a tag/ref */
-
- if ((obj = H5Dopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open H5 dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to convert to tag/ref\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- }
- }
- if ((status = H5Dclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- } else { /* flag == FALSE */
-
- if ((obj = H5Dopen (group, name)) <= 0 ) {
- fprintf(stderr,"Error: Unable to open H5 dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- return (obj);
- } else {
- if (( status = convert_dataset (obj, name, op_data)) != SUCCEED) {
- fprintf(stderr,"Error: convert_dataset did not work for %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
- if ((status = convert_shared_dataset(obj, idx, op_data)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to convert to tag/ref\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- }
- if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
- fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- break;
- }
- }
- if ((status = H5Dclose(obj)) != SUCCEED) {
- fprintf(stderr,"Error: Unable to close H5 dataset %s\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
- status = FAIL;
- break;
- }
-
- }
-
- break;
-
- case H5G_TYPE:
- /* object is ignored */
- break;
-
- default:
- fprintf (stderr,"Unknown Object %s\n", name);
- status = FAIL;
- break;
-
- }
-
- *op_data = op_data_save;
-
- return SUCCEED;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_shared_dataset
- *
- * Purpose: Handle a shared dataset which has already been converted.
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_shared_dataset(hid_t did, int idx, op_data_t *op_data)
-{
- int status=SUCCEED;
- int32 vgroup_id;
- char *dataset_name=NULL;
- char *dataset_name2=NULL;
- int32 hfile_id;
- int32 sd_id;
- int32 sds_id;
- int32 sds_ref;
- int32 vdata_ref;
- int32 sds_index;
- int32 numtagref;
- hid_t type, space, class;
- hsize_t dims[32], maxdims[32];
- int n_values, ndims;
-
- vgroup_id = op_data->vgroup_id;
-
- if ((dataset_name = get_objectname(dset_table, idx)) == NULL ) {
- fprintf(stderr,"Error: get_objectname() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (status);
- }
-
- if ((dataset_name2 = strrchr(dataset_name,'/')) == NULL) { /* find last "/" in dataset_name */
- dataset_name2 = dataset_name; /* no "/"s were found */
- } else {
- dataset_name2 = dataset_name2 + sizeof(char); /* 1 character past last "/" */
- }
-
- if ((type = H5Dget_type(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((space = H5Dget_space(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
- fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((ndims = H5Sget_simple_extent_dims(space,dims,maxdims)) < 0 ) {
- fprintf(stderr, "Error: Problems getting ndims, dims, and maxdims of dataset\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = ndims;
- return status;
- }
-
- if ((class = H5Tget_class(type)) < 0 ) {
- fprintf(stderr,"Error: problem with getting class\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = class;
- return status;
- }
-
- switch (class) {
- case H5T_INTEGER:
- case H5T_FLOAT:
- sd_id = op_data->sd_id;
- if ((sds_index = SDnametoindex(sd_id, dataset_name2)) < 0 ) {
- fprintf (stderr,"Error: Problem with SDnametoindex().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (sds_index);
- }
- if ((sds_id = SDselect(sd_id, sds_index)) < 0 ) {
- fprintf (stderr,"Error: Problem with SDselect().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (sds_id);
- }
- if ((sds_ref = SDidtoref(sds_id)) < 0 ) {
- fprintf (stderr,"Error: Problem with SDidtoref().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (sds_ref);
- }
- if ((numtagref = Vaddtagref(vgroup_id, DFTAG_NDG, sds_ref)) < 0 ) {
- fprintf (stderr,"Error: Problem with Vaddtagref().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (numtagref);
- }
- break;
- case H5T_TIME:
- fprintf(stderr,"Error: H5T_TIME not yet implemented.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- break;
- case H5T_STRING:
- hfile_id = op_data->hfile_id;
- if (ndims==1) {
- if ((vdata_ref = VSfind(hfile_id,dataset_name2)) <= 0 ) {
- fprintf (stderr,"Error: Problem with VSfind().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (vdata_ref);
- }
- if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VH, vdata_ref)) < 0 ) {
- fprintf (stderr,"Error: Problem with Vaddtagref().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (numtagref);
- }
- }
- break;
- case H5T_BITFIELD:
- fprintf(stderr,"Error: H5T_BITFIELD not yet implemented.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- break;
- case H5T_OPAQUE:
- fprintf(stderr,"Error: H5T_OPAQUE not yet implemented.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- break;
- case H5T_COMPOUND:
- hfile_id = op_data->hfile_id;
- if (ndims==1) {
- if ((vdata_ref = VSfind(hfile_id,dataset_name2)) <= 0 ) {
- fprintf (stderr,"Error: Problem with VSfind().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (vdata_ref);
- }
- if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VH, vdata_ref)) < 0 ) {
- fprintf (stderr,"Error: Problem with Vaddtagref().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- return (numtagref);
- }
- }
- break;
- default:
- fprintf(stderr,"Error: %d class not found\n",class);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = FAIL;
- }
-
- if ((status = H5Tclose(type)) < 0 ) {
- fprintf(stderr,"Error: closing type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- status = FAIL;
- }
-
- if (dataset_name != NULL) {
- HDfree (dataset_name);
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_shared_group
- *
- * Purpose: Handle a shared group which has already been converted.
- *
- * Return: status
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_shared_group (hid_t group, int idx, op_data_t *op_data) {
-
- int32 hfile_id;
- int32 vgroup_id;
- int32 vgroup_ref;
- int32 numtagref;
- int32 status = SUCCEED;
- hid_t group2;
- char *group_name=NULL;
- char *group_name2=NULL;
- char vgroup_name[VGNAMELENMAX];
-
- group2 = group;
- hfile_id = op_data->hfile_id;
-
- if ((group_name = get_objectname(group_table, idx)) == NULL ) {
- fprintf(stderr,"Error: get_objectname() did not work\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- status = FAIL;
- return (status);
- }
-
- if ((group_name2 = strrchr(group_name,'/')) == NULL) { /* find last "/" in group_name */
- group_name2 = group_name; /* no "/"s were found */
- } else {
- group_name2 = group_name2 + sizeof(char); /* 1 character past last "/" */
- }
-
- if ((status = Vgetname(op_data->vgroup_id,vgroup_name)) < 0 ) {
- fprintf (stderr,"Error: Problem with Vfind().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- return (status);
- }
-
- if ((vgroup_ref = Vfind(hfile_id,vgroup_name)) <= 0 ) {
- fprintf (stderr,"Error: Problem with Vfind().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- return (vgroup_ref);
- }
-
- if ((vgroup_id = Vattach(hfile_id, vgroup_ref, "w")) <= 0 ) {
- fprintf(stderr,"Error: Unable to create new vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- return(vgroup_id);
- }
-
- if ((vgroup_ref = Vfind(hfile_id,group_name2)) <= 0 ) {
- fprintf (stderr,"Error: Problem with Vfind().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- return (vgroup_ref);
- }
-
- if ((numtagref = Vaddtagref(vgroup_id, DFTAG_VG, vgroup_ref)) < 0 ) {
- fprintf (stderr,"Error: Problem with Vaddtagref().\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- return (numtagref);
- }
-
- if ((status = Vdetach(vgroup_id)) != SUCCEED ) {
- fprintf(stderr,"Error: Unable to detach the new Vgroup\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
- status = FAIL;
- }
-
- if (group_name != NULL) {
- HDfree(group_name);
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: convert_dataset_string
- *
- * Purpose: convert a dataset with string elements.
- *
- * Return: status
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-convert_dataset_string (hid_t did, char *name, op_data_t *op_data) {
-
- int32 hfile_id;
- int32 vgroup_id;
- int32 vdata_id;
-hid_t fxdlenstr, space, class, mem_type;
-const char* fieldname = {"string"};
-const char* fieldname_list = fieldname;
-char *buffer;
-int32 status;
-int32 h4_type;
-int32 recsize, n_records, n_values, num_of_recs, record_pos;
-size_t lenstr;
-H5T_cset_t cset;
-H5T_str_t strpad;
-
- if ((fxdlenstr = H5Dget_type(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_type() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((class = H5Tget_class(fxdlenstr)) != H5T_STRING ) {
- fprintf(stderr,"Error: problem with getting class\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
- status = class;
- return status;
- }
-
- if ((space = H5Dget_space(did)) <= 0) {
- fprintf(stderr, "Error: H5Dget_space() didn't return appropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- if ((n_values = H5Sget_simple_extent_npoints(space)) <= 0) {
- fprintf(stderr, "Error: H5Sget_simple_extent_npoints() returned inappropriate value.\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- h4_type = DFNT_CHAR;
- if ((mem_type = H5Tcopy(H5T_C_S1)) == FAIL ) {
- fprintf(stderr, "Error: Problems translating h4 type to mem type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = mem_type;
- return status;
- }
- if ((lenstr = H5Tget_size(fxdlenstr)) <= 0 ) {
- fprintf(stderr, "Error: size of fixed length string type should not be %d\n",(int)lenstr);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return lenstr;
- }
- if ((status = H5Tset_size(mem_type,lenstr)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_size()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- strpad = H5Tget_strpad(fxdlenstr);
- if ((strpad != H5T_STR_NULLTERM) && (strpad != H5T_STR_NULLPAD) && (strpad != H5T_STR_SPACEPAD)) {
- fprintf(stderr, "Error: Invalid string padding value, %d\n",(int)strpad);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return strpad;
- }
- if ((status = H5Tset_strpad(mem_type, strpad)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_strpad()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- if ((cset = H5Tget_cset(fxdlenstr)) != H5T_CSET_ASCII ) {
- fprintf(stderr, "Error: cset value != %d\n",(int)H5T_CSET_ASCII);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return cset;
- }
- if ((status = H5Tset_cset(mem_type,cset)) != SUCCEED ) {
- fprintf(stderr, "Error: Problem with H5Tset_cset()\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- hfile_id = op_data->hfile_id;
- vgroup_id = op_data->vgroup_id;
- if ((vdata_id = VSattach(hfile_id, -1, "w")) <= 0 ) {
- fprintf(stderr, "Error: Unable to create vdata %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
-
- op_data->vdata_id = vdata_id;
- if ((status = VSsetname(vdata_id, name)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set vdata name %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
- if ((status = VSsetclass(vdata_id, "HDF5")) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set class on vdata %s\n", name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- if ((status = VSfdefine(vdata_id, fieldname, h4_type, lenstr)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to VSfdefine() field\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- if ((status = VSsetfields(vdata_id, fieldname_list)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set fieldname list %s\n", fieldname_list);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
- if ((status = VSsetinterlace(vdata_id, FULL_INTERLACE)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to set FULL_INTERLACE mode, status %d\n", (int)status);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
- if ((recsize = H5Tget_size(mem_type)) <= 0 ) {
- fprintf(stderr, "Error: Unable to get record size %d\n", (int)recsize);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = recsize;
- return status;
- }
-/*
- Since the space is rank 1, n_records does not depend on maxdims.
-*/
- n_records = n_values;
- if ((buffer = HDmalloc(n_records*recsize)) == NULL) {
- fprintf(stderr, "Error: Problems with HDmalloc of memory space\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = FAIL;
- return status;
- }
- if ((status = H5Dread(did, mem_type, space, space, H5P_DEFAULT, buffer)) != SUCCEED) {
- fprintf(stderr, "Error: Problems with H5Dread\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- if ((record_pos = VSseek(vdata_id, 0)) != 0 ) {
- fprintf(stderr, "Error: Could not seek the beginning of the Vdata, %d\n", (int)record_pos);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = record_pos;
- return status;
- }
- if ((num_of_recs = VSwrite(vdata_id, (void *)buffer, n_records, FULL_INTERLACE)) != n_records ) {
- fprintf(stderr, "Error: Only able to write %d of %d records\n", (int)num_of_recs, (int)n_records);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- status = num_of_recs;
- return status;
- }
-
- /* there are only vdata attributes, no field attributes */
- if ((status = H5Aiterate(did, NULL, (H5A_operator_t)convert_attr, op_data)) < 0 ) {
- fprintf(stderr,"Error: iterate over attributes\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
- if ((status = VSdetach(vdata_id)) != SUCCEED ) {
- fprintf(stderr, "Error: Unable to detach to vdata %s.\n",name);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset_string", __FILE__, __LINE__);
- return status;
- }
-
- if (buffer != NULL) {
- HDfree(buffer);
- }
-
- return status;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: h5atomic_type_to_h4type
- *
- * Purpose: Match an H5 atomic type to an appropriate H4 type.
- * Assign an appropirate H5 memory type that matches the H4 type.
- * Return the H5 memory type, H4 type and sizeof H4 via pointers.
- *
- * Return: SUCCEED on suceed, FAIL on failure.
- * When fail, pointer values of h5memtype, h5memsize and h4_type
- * may have changed and are undefined.
- *
- * Programmer: Albert Cheng, March 2000
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type)
-{
- H5T_class_t class;
- size_t h5typesize, h4typesize;
- H5T_sign_t sign;
- hid_t mem_datatype = FAIL;
-
- if ((class = H5Tget_class(h5type)) < 0 ) {
- fprintf(stderr,"Error: problem with getting type class\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
-
- switch(class){
- case H5T_INTEGER:
- if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
- fprintf(stderr,"Error: problem with getting type size\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
- if ((sign = H5Tget_sign(h5type)) == H5T_SGN_ERROR) {
- fprintf(stderr,"Error: problem with getting type sign\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
- /* deduce the proper HDF4 integer type to use according to the size of the HDF5 type. */
- /* Current HDF4 types can be 8, 16, 32 bits (1, 2, 4 bytes). */
- switch(h5typesize){
- case 1:
- *h4type = (sign == H5T_SGN_2 ? DFNT_INT8 : DFNT_UINT8);
- h4typesize = sizeof(int8);
- if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
- }else
- return(FAIL);
- break;
- case 2:
- *h4type = (sign == H5T_SGN_2 ? DFNT_INT16 : DFNT_UINT16);
- h4typesize = sizeof(int16);
- if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
- }else
- return(FAIL);
- break;
- case 4:
- *h4type = (sign == H5T_SGN_2 ? DFNT_INT32 : DFNT_UINT32);
- h4typesize = sizeof(int32);
- if (h4typesize == H5Tget_size(H5T_NATIVE_CHAR)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SCHAR : H5T_NATIVE_UCHAR);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_SHORT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_INT)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_INT : H5T_NATIVE_UINT);
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_LONG)){
- mem_datatype = (sign == H5T_SGN_2 ? H5T_NATIVE_LONG : H5T_NATIVE_ULONG);
- }else
- return(FAIL);
- break;
- default:
- fprintf(stderr,"Error: unmatchable integer type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
- break;
- /* end of case H5T_INTEGER */
-
- case H5T_FLOAT:
- if ((h5typesize = H5Tget_size(h5type)) == 0 ) {
- fprintf(stderr,"Error: problem with getting type size\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
- /* deduce the proper HDF4 floating point type to use according to the size of the HDF5 type. */
- /* Current HDF4 types can be 32 or 64 bits (4 or 8 bytes). */
- switch(h5typesize){
- case 4:
- *h4type = DFNT_FLOAT32;
- h4typesize = sizeof(float32);
- if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
- mem_datatype = H5T_NATIVE_FLOAT;
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
- mem_datatype = H5T_NATIVE_DOUBLE;
- }else
- return(FAIL);
- break;
- case 8:
- *h4type = DFNT_FLOAT64;
- h4typesize = sizeof(float64);
- if (h4typesize == H5Tget_size(H5T_NATIVE_FLOAT)){
- mem_datatype = H5T_NATIVE_FLOAT;
- }else if (h4typesize == H5Tget_size(H5T_NATIVE_DOUBLE)){
- mem_datatype = H5T_NATIVE_DOUBLE;
- }else
- return(FAIL);
- break;
- default:
- fprintf(stderr,"Error: unmatchable H5 float type\n");
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5atomic_type_to_h4type", __FILE__, __LINE__);
- return FAIL;
- }
- break;
- /* end of case H5T_FLOAT */
-
- default:
- return FAIL;
- }
-
- *h5memsize = h4typesize;
- *h5memtype = mem_datatype;
- return(SUCCEED);
-}
-#ifndef NEWWAY
-/*****************************************************************************
-
- Routine: h5type_to_h4type(h5type)
-
- Description: Translate h5 datatype into h4 datatype
-
- Input: h5 datatype
-
- Output: function return, h4 datatype
-
-*****************************************************************************/
-
-int32 h5type_to_h4type(hid_t h5_datatype)
-{
- int32 h4_datatype;
-
- if (H5Tequal(h5_datatype,H5T_STD_I8BE)) {
- h4_datatype = DFNT_INT8;
- } else if (H5Tequal(h5_datatype,H5T_STD_I16BE)) {
- h4_datatype = DFNT_INT16;
- } else if (H5Tequal(h5_datatype,H5T_STD_I32BE)) {
- h4_datatype = DFNT_INT32;
-/*
- * This is not supported by HDF4
- *
- } else if (H5Tequal(h5_datatype,H5T_STD_I64BE)) {
- h4_datatype = DFNT_INT64;
-*/
- } else if (H5Tequal(h5_datatype,H5T_STD_U8BE)) {
- h4_datatype = DFNT_UINT8;
- } else if (H5Tequal(h5_datatype,H5T_STD_U16BE)) {
- h4_datatype = DFNT_UINT16;
- } else if (H5Tequal(h5_datatype,H5T_STD_U32BE)) {
- h4_datatype = DFNT_UINT32;
- } else if (H5Tequal(h5_datatype,H5T_STD_U64BE)) {
- h4_datatype = DFNT_UINT64;
- } else if (H5Tequal(h5_datatype,H5T_IEEE_F32BE)) {
- h4_datatype = DFNT_FLOAT32;
- } else if (H5Tequal(h5_datatype,H5T_IEEE_F64BE)) {
- h4_datatype = DFNT_FLOAT64;
- } else if (H5Tequal(h5_datatype,H5T_STD_I8LE)) {
- h4_datatype = DFNT_INT8;
- } else if (H5Tequal(h5_datatype,H5T_STD_I16LE)) {
- h4_datatype = DFNT_INT16;
- } else if (H5Tequal(h5_datatype,H5T_STD_I32LE)) {
- h4_datatype = DFNT_INT32;
-/*
- * This is not supported by HDF4
- *
- } else if (H5Tequal(h5_datatype,H5T_STD_I64LE)) {
- h4_datatype = DFNT_INT64;
-*/
- } else if (H5Tequal(h5_datatype,H5T_STD_U8LE)) {
- h4_datatype = DFNT_UINT8;
- } else if (H5Tequal(h5_datatype,H5T_STD_U16LE)) {
- h4_datatype = DFNT_UINT16;
- } else if (H5Tequal(h5_datatype,H5T_STD_U32LE)) {
- h4_datatype = DFNT_UINT32;
- } else if (H5Tequal(h5_datatype,H5T_STD_U64LE)) {
- h4_datatype = DFNT_UINT64;
- } else if (H5Tequal(h5_datatype,H5T_IEEE_F32LE)) {
- h4_datatype = DFNT_FLOAT32;
- } else if (H5Tequal(h5_datatype,H5T_IEEE_F64LE)) {
- h4_datatype = DFNT_FLOAT64;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_SCHAR)) {
- h4_datatype = DFNT_INT8;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_UCHAR)) {
- h4_datatype = DFNT_UINT8;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_SHORT)) {
- h4_datatype = DFNT_INT16;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_USHORT)) {
- h4_datatype = DFNT_UINT16;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_INT)) {
- h4_datatype = DFNT_INT32;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_UINT)) {
- h4_datatype = DFNT_UINT32;
-/*
- * This is not supported by HDF4
- *
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_LONG)) {
- h4_datatype = DFNT_INT64;
-*/
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_ULONG)) {
- h4_datatype = DFNT_UINT64;
-/*
- * This is not supported by HDF4
- *
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_LLONG)) {
- h4_datatype = DFNT_INT128;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_ULLONG)) {
- h4_datatype = DFNT_UINT128;
-*/
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_FLOAT)) {
- h4_datatype = DFNT_FLOAT32;
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_DOUBLE)) {
- h4_datatype = DFNT_FLOAT64;
-/*
- * This is not supported by HDF4
- *
- } else if (H5Tequal(h5_datatype,H5T_NATIVE_LDOUBLE)) {
- h4_datatype = DFNT_FLOAT128;
-*/
- } else {
- h4_datatype = FAIL;
- }
-
- return h4_datatype;
-
-}
-
-
-/*****************************************************************************
-
- Routine: h4type_to_memtype(h4type)
-
- Description: Translate h4 datatype into mem datatype
-
- Input: h4 datatype
-
- Output: function return, mem datatype
-
-*****************************************************************************/
-
-hid_t h4type_to_memtype(int32 h4_datatype)
-{
- hid_t mem_datatype;
-
- switch (h4_datatype) {
- case DFNT_INT8:
- case DFNT_NINT8:
- case DFNT_LINT8:
- mem_datatype = H5T_NATIVE_SCHAR; break;
- case DFNT_UINT8:
- case DFNT_NUINT8:
- case DFNT_LUINT8:
- mem_datatype = H5T_NATIVE_UCHAR; break;
- case DFNT_INT16:
- case DFNT_NINT16:
- case DFNT_LINT16:
- mem_datatype = H5T_NATIVE_SHORT; break;
- case DFNT_UINT16:
- case DFNT_NUINT16:
- case DFNT_LUINT16:
- mem_datatype = H5T_NATIVE_USHORT; break;
- case DFNT_INT32:
- case DFNT_NINT32:
- case DFNT_LINT32:
- mem_datatype = H5T_NATIVE_INT; break;
- case DFNT_UINT32:
- case DFNT_NUINT32:
- case DFNT_LUINT32:
- mem_datatype = H5T_NATIVE_UINT; break;
- case DFNT_INT64:
- case DFNT_NINT64:
- case DFNT_LINT64:
- mem_datatype = H5T_NATIVE_LONG; break;
- case DFNT_UINT64:
- case DFNT_NUINT64:
- case DFNT_LUINT64:
- mem_datatype = H5T_NATIVE_ULONG; break;
- case DFNT_INT128:
- case DFNT_NINT128:
- case DFNT_LINT128:
- mem_datatype = H5T_NATIVE_LLONG; break;
- case DFNT_UINT128:
- case DFNT_NUINT128:
- case DFNT_LUINT128:
- mem_datatype = H5T_NATIVE_ULLONG; break;
- case DFNT_FLOAT32:
- case DFNT_NFLOAT32:
- case DFNT_LFLOAT32:
- mem_datatype = H5T_NATIVE_FLOAT; break;
- case DFNT_FLOAT64:
- case DFNT_NFLOAT64:
- case DFNT_LFLOAT64:
- mem_datatype = H5T_NATIVE_DOUBLE; break;
- case DFNT_FLOAT128:
- case DFNT_NFLOAT128:
- case DFNT_LFLOAT128:
- mem_datatype = H5T_NATIVE_LDOUBLE; break;
- default:
- mem_datatype = FAIL;
- }
-
- return mem_datatype;
-
-}
-#endif
-
-
-/*****************************************************************************
-
- Routine: test_file
-
- Description: Test a file for read/write - ability.
-
- Input: filename - Unix filename
-
- Output: function return, global variable - errno
-
-*****************************************************************************/
-
-int test_file(char *filename,int oflag,mode_t mode)
-{
- int fid;
-
- errno = 0;
-
- fid = open(filename, oflag, mode);
- if (fid < 0) {
- perror(filename);
- }
- close(fid);
-
- return errno;
-
-}
-
-
-/*****************************************************************************
-
- Routine: test_dir
-
- Description: Test pathway to determine if it is a directory
-
- Input: path - pathname given
-
- Output: function return TRUE/FALSE
-
-*****************************************************************************/
-
-int test_dir(char *path)
-{
-
- struct stat buf;
- struct stat *buf_ptr;
- int idir;
-
- buf_ptr = &buf;
-
- idir = stat(path, buf_ptr);
- if (idir < 0) {
- if (errno == 2) {
- return 0;
- } else {
- perror(path);
- }
- }
-
- return S_ISDIR(buf_ptr->st_mode);
-}
-
-/*****************************************************************************
-
- Routine: BuildFilename()
-
- Description: Build a filename with new extension
-
- Input: filename - present filename
- ext - extension to root of filename
-
- Output: (filename:r).ext
-
-*****************************************************************************/
-
-char *BuildFilename(char *filename, char *ext)
-{
- /* build outgoing filename */
-
- char *filename_out;
- char *lastper_ptr, *lastdir_ptr;
- int root_len;
-
- lastper_ptr = strrchr(filename,'.');
- lastdir_ptr = strrchr(filename,'/');
-
- if ( lastper_ptr <= lastdir_ptr ) { /* no extension */
- root_len = strlen(filename);
- } else { /* existing extension */
- root_len = (int)(lastper_ptr - filename);
- }
-
- filename_out = (char *)HDmalloc(root_len + strlen(ext) + 2);
- filename_out = strncpy(filename_out, filename, (size_t)root_len);
- filename_out[root_len] = '\0';
- filename_out = strcat(filename_out,".");
- filename_out = strcat(filename_out,ext);
-
- return filename_out;
-}
-
diff --git a/tools/h5toh4.h b/tools/h5toh4.h
deleted file mode 100644
index d268060..0000000
--- a/tools/h5toh4.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright © 1998 NCSA
- * All rights reserved.
- *
- * Programmer: Paul Harten <pharten@ncsa.uiuc.edu>
- * Friday, October 16th, 1998
- *
- * Purpose: Convert H5 files to H4 files.
- */
-
-#ifndef _H5TOH4_H
-#define _H5TOH4_H
-
-#include "hdf.h"
-#include "mfhdf.h"
-#include "hdf5.h"
-
-#ifdef H5_HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
-typedef struct op_data_t {
- /*
- * information being carried between iterations.
- *
- */
-
- int32 hfile_id;
- int32 vgroup_id;
- int32 sd_id;
- int32 sds_id;
- int32 vdata_id;
- int32 obj_idx;
-
-} op_data_t;
-
-#ifdef H5TOH4_DEBUG
-#define DEBUG_PRINT(s1,s2,s3,n1) ( fprintf(stderr,s1,s2,s3,n1) )
-#else
-#define DEBUG_PRINT(s1,s2,s3,n1) ( fprintf(stderr," ") )
-#endif
-
-#endif
diff --git a/tools/h5tools.c b/tools/h5tools.c
deleted file mode 100644
index 46f2e68..0000000
--- a/tools/h5tools.c
+++ /dev/null
@@ -1,2688 +0,0 @@
-/*
- * Copyright © 1998, 2001 National Center for Supercomputing Applications
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Thursday, July 23, 1998
- *
- * Purpose: A library for displaying the values of a dataset in a human
- * readable format.
- */
-
-/*
- * Portions of this work are derived from _Obfuscated C and Other Mysteries_,
- * by Don Libes, copyright (c) 1993 by John Wiley & Sons, Inc.
- */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "h5tools.h"
-#include "hdf5.h"
-#include "H5private.h"
-#include "h5dump.h"
-
-/* taken from h5dumputil.c */
-
-/*
- * If REPEAT_VERBOSE is defined then character strings will be printed so
- * that repeated character sequences like "AAAAAAAAAA" are displayed as
- *
- * 'A' repeates 9 times
- *
- * Otherwise the format is more Perl-like
- *
- * 'A'*10
- *
- */
-#define REPEAT_VERBOSE
-
-/*
- * The output functions need a temporary buffer to hold a piece of the
- * dataset while it's being printed. This constant sets the limit on the
- * size of that temporary buffer in bytes. For efficiency's sake, choose the
- * largest value suitable for your machine (for testing use a small value).
- */
-#if 1
-#define H5DUMP_BUFSIZE (1024 * 1024)
-#else
-#define H5DUMP_BUFSIZE (1024)
-#endif
-
-#define OPT(X,S) ((X) ? (X) : (S))
-#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z))
-#define START_OF_DATA 0x0001
-#define END_OF_DATA 0x0002
-
-/* Special strings embedded in the output */
-#define OPTIONAL_LINE_BREAK "\001"
-
-/* Variable length string datatype */
-#define STR_INIT_LEN 4096 /*initial length */
-
-/* module-scoped variables */
-static int h5tools_init_g; /* if h5tools lib has been initialized */
-
-int indent;
-int compound_data;
-int nCols = 80;
-FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */
-
-/* ``get_option'' variables */
-int opt_err = 1; /*get_option prints errors if this is on */
-int opt_ind = 1; /*token pointer */
-const char *opt_arg; /*flag argument (or value) */
-
-typedef struct h5dump_str_t {
- char *s; /*allocate string */
- size_t len; /*length of actual value */
- size_t nalloc; /*allocated size of string */
-} h5dump_str_t;
-
-/* Output variables */
-typedef struct h5dump_context_t {
- size_t cur_column; /*current column for output */
- size_t cur_elmt; /*current element/output line */
- int need_prefix; /*is line prefix needed? */
- int ndims; /*dimensionality */
- hsize_t p_min_idx[H5S_MAX_RANK]; /*min selected index */
- hsize_t p_max_idx[H5S_MAX_RANK]; /*max selected index */
- int prev_multiline; /*was prev datum multiline? */
- size_t prev_prefix_len;/*length of previous prefix */
- int continuation; /*continuation of previous data?*/
- int size_last_dim; /*the size of the last dimension,
- *needed so we can break after each
- *row */
- int indent_level; /*the number of times we need some
- *extra indentation */
- int default_indent_level; /*this is used when the indent
- *level gets changed */
-} h5dump_context_t;
-
-typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
-
-extern void free_table(table_t **table);
-extern void dump_table(char *name, table_t* table);
-extern int get_table_idx(table_t *table, unsigned long *);
-extern int get_tableflag(table_t*, int);
-extern int set_tableflag(table_t*, int);
-extern char *get_objectname(table_t*, int);
-
-
-/*-------------------------------------------------------------------------
- * Function: get_option
- *
- * Purpose: Determine the command-line options a user specified. We can
- * accept both short and long type command-lines.
- *
- * Return: Success: The short valued "name" of the command line
- * parameter or EOF if there are no more
- * parameters to process.
- *
- * Failure: A question mark.
- *
- * Programmer: Bill Wendling
- * Friday, 5. January 2001
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-get_option(int argc, const char **argv, const char *opts, const struct long_options *l_opts)
-{
- static int sp = 1; /* character index in current token */
- int opt_opt = '?'; /* option character passed back to user */
-
- if (sp == 1) {
- /* check for more flag-like tokens */
- if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0') {
- return EOF;
- } else if (strcmp(argv[opt_ind], "--") == 0) {
- opt_ind++;
- return EOF;
- }
- }
-
- if (sp == 1 && argv[opt_ind][0] == '-' && argv[opt_ind][1] == '-') {
- /* long command line option */
- const char *arg = &argv[opt_ind][2];
- register int i;
-
- for (i = 0; l_opts && l_opts[i].name; i++) {
- size_t len = strlen(l_opts[i].name);
-
- if (strncmp(arg, l_opts[i].name, len) == 0) {
- /* we've found a matching long command line flag */
- opt_opt = l_opts[i].shortval;
-
- if (l_opts[i].has_arg != no_arg) {
- if (arg[len] == '=') {
- opt_arg = &arg[len + 1];
- } else if (opt_ind < (argc - 1) && argv[opt_ind + 1][0] != '-') {
- opt_arg = argv[++opt_ind];
- } else if (l_opts[i].has_arg == require_arg) {
- if (opt_err)
- fprintf(stderr,
- "%s: option required for \"--%s\" flag\n",
- argv[0], arg);
-
- opt_opt = '?';
- }
- } else {
- if (arg[len] == '=') {
- if (opt_err)
- fprintf(stderr,
- "%s: no option required for \"%s\" flag\n",
- argv[0], arg);
-
- opt_opt = '?';
- }
-
- opt_arg = NULL;
- }
-
- break;
- }
- }
-
- if (l_opts[i].name == NULL) {
- /* exhausted all of the l_opts we have and still didn't match */
- if (opt_err)
- fprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg);
-
- opt_opt = '?';
- }
-
- opt_ind++;
- sp = 1;
- } else {
- register char *cp; /* pointer into current token */
-
- /* short command line option */
- opt_opt = argv[opt_ind][sp];
-
- if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0) {
- if (opt_err)
- fprintf(stderr, "%s: unknown option \"%c\"\n",
- argv[0], opt_opt);
-
- /* if no chars left in this token, move to next token */
- if (argv[opt_ind][++sp] == '\0') {
- opt_ind++;
- sp = 1;
- }
-
- return '?';
- }
-
- if (*++cp == ':') {
- /* if a value is expected, get it */
- if (argv[opt_ind][sp + 1] != '\0') {
- /* flag value is rest of current token */
- opt_arg = &argv[opt_ind++][sp + 1];
- } else if (++opt_ind >= argc) {
- if (opt_err)
- fprintf(stderr,
- "%s: value expected for option \"%c\"\n",
- argv[0], opt_opt);
-
- opt_opt = '?';
- } else {
- /* flag value is next token */
- opt_arg = argv[opt_ind++];
- }
-
- sp = 1;
- } else {
- /* set up to look at next char in token, next time */
- if (argv[opt_ind][++sp] == '\0') {
- /* no more in current token, so setup next token */
- opt_ind++;
- sp = 1;
- }
-
- opt_arg = NULL;
- }
- }
-
- /* return the current flag character found */
- return opt_opt;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5tools_init
- *
- * Purpose: Initialize the H5 Tools library.
- * This should be called before any other h5tools function is
- * called. Effect of any h5tools function called before this
- * has been called is undetermined.
- *
- * Return: None
- *
- * Programmer: Albert Cheng, 2000-10-31
- *
- * Modifications:
- *-------------------------------------------------------------------------
- */
-void
-h5tools_init(void)
-{
- if (!h5tools_init_g) {
- if (!rawdatastream)
- rawdatastream = stdout;
-
- h5tools_init_g++;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5tools_close
- *
- * Purpose: Close the H5 Tools library by closing or releasing resources
- * such as files opened by the library.
- * This should be called after all other h5tools functions have
- * been called. Effect of any h5tools function called after this
- * has been called is undetermined.
- *
- * Return: None
- *
- * Programmer: Albert Cheng, 2000-10-31
- *
- * Modifications:
- *-------------------------------------------------------------------------
- */
-void
-h5tools_close(void)
-{
- if (h5tools_init_g) {
- if (rawdatastream && rawdatastream != stdout) {
- if (fclose(rawdatastream))
- perror("closing rawdatastream");
- else
- rawdatastream = NULL;
- }
-
- h5tools_init_g = 0;
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_close
- *
- * Purpose: Closes a string by releasing it's memory and setting the size
- * information to zero.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-h5dump_str_close(h5dump_str_t *str)
-{
- if (str && str->nalloc) {
- free(str->s);
- memset(str, 0, sizeof(h5dump_str_t));
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_len
- *
- * Purpose: Returns the length of the string, not counting the null
- * terminator.
- *
- * Return: Success: Length of string
- *
- * Failure: 0
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static size_t
-h5dump_str_len(h5dump_str_t *str)
-{
- return str->len;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_append
- *
- * Purpose: Formats variable arguments according to printf() format
- * string and appends the result to variable length string STR.
- *
- * Return: Success: Pointer to buffer containing result.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_str_append(h5dump_str_t *str/*in,out*/, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
-
- /* Make sure we have some memory into which to print */
- if (!str->s || str->nalloc <= 0) {
- str->nalloc = STR_INIT_LEN;
- str->s = malloc(str->nalloc);
- assert(str->s);
- str->s[0] = '\0';
- str->len = 0;
- }
-
- while (1) {
- size_t avail = str->nalloc - str->len;
- size_t nchars = (size_t)HDvsnprintf(str->s+str->len, avail, fmt, ap);
-
- if (nchars < avail) {
- /* success */
- str->len += nchars;
- break;
- }
-
- /* Try again with twice as much space */
- str->nalloc *= 2;
- str->s = realloc(str->s, str->nalloc);
- assert(str->s);
- }
-
- va_end(ap);
- return str->s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_reset
- *
- * Purpose: Reset the string to the empty value. If no memory is
- * allocated yet then initialize the h5dump_str_t struct.
- *
- * Return: Success: Ptr to the buffer which contains a null
- * character as the first element.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_str_reset(h5dump_str_t *str/*in,out*/)
-{
- if (!str->s || str->nalloc <= 0) {
- str->nalloc = STR_INIT_LEN;
- str->s = malloc(str->nalloc);
- assert(str->s);
- }
-
- str->s[0] = '\0';
- str->len = 0;
- return str->s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_trunc
- *
- * Purpose: Truncate a string to be at most SIZE characters.
- *
- * Return: Success: Pointer to the string
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_str_trunc(h5dump_str_t *str/*in,out*/, size_t size)
-{
- if (size < str->len) {
- str->len = size;
- str->s[size] = '\0';
- }
-
- return str->s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_str_fmt
- *
- * Purpose: Reformat a string contents beginning at character START
- * according to printf format FMT. FMT should contain no format
- * specifiers except possibly the `%s' variety. For example, if
- * the input string is `hello' and the format is "<<%s>>" then
- * the output value will be "<<hello>>".
- *
- * Return: Success: A pointer to the resulting string.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_str_fmt(h5dump_str_t *str/*in,out*/, size_t start, const char *fmt)
-{
- char _temp[1024], *temp = _temp;
-
- /* If the format string is simply "%s" then don't bother doing anything */
- if (!strcmp(fmt, "%s"))
- return str->s;
-
- /*
- * Save the input value if there is a `%' anywhere in FMT. Otherwise
- * don't bother because we don't need a temporary copy.
- */
- if (strchr(fmt, '%')) {
- if (str->len - start + 1 > sizeof(_temp)) {
- temp = malloc(str->len-start + 1);
- assert(temp);
- }
-
- strcpy(temp, str->s + start);
- }
-
- /* Reset the output string and append a formatted version */
- h5dump_str_trunc(str, start);
- h5dump_str_append(str, fmt, temp);
-
- /* Free the temp buffer if we allocated one */
- if (temp != _temp)
- free(temp);
-
- return str->s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_prefix
- *
- * Purpose: Renders the line prefix value into string STR.
- *
- * Return: Success: Pointer to the prefix.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_prefix(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
- hsize_t elmtno, int ndims, hsize_t min_idx[], hsize_t max_idx[])
-{
- hsize_t p_prod[H5S_MAX_RANK], p_idx[H5S_MAX_RANK];
- hsize_t n, i = 0;
-
- h5dump_str_reset(str);
-
- if (ndims > 0) {
- /*
- * Calculate the number of elements represented by a unit change in a
- * certain index position.
- */
- for (i = ndims - 1, p_prod[ndims - 1] = 1; i > 0; --i) {
- p_prod[i - 1] = (max_idx[i] - min_idx[i]) * p_prod[i];
- }
-
- /*
- * Calculate the index values from the element number.
- */
- for (i = 0, n = elmtno; i < (hsize_t)ndims; i++) {
- p_idx[i] = n / p_prod[i] + min_idx[i];
- n %= p_prod[i];
- }
-
- /*
- * Print the index values.
- */
- for (i = 0; i < (hsize_t)ndims; i++) {
- if (i)
- h5dump_str_append(str, "%s", OPT(info->idx_sep, ","));
-
- h5dump_str_append(str, OPT(info->idx_n_fmt, "%lu"),
- (unsigned long)p_idx[i]);
- }
- } else {
- /* Scalar */
- h5dump_str_append(str, OPT(info->idx_n_fmt, "%lu"), (unsigned long)0);
- }
-
- /*
- * Add prefix and suffix to the index.
- */
- return h5dump_str_fmt(str, 0, OPT(info->idx_fmt, "%s: "));
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_escape
- *
- * Purpose: Changes all "funny" characters in S into standard C escape
- * sequences. If ESCAPE_SPACES is non-zero then spaces are
- * escaped by prepending a backslash.
- *
- * Return: Success: S
- *
- * Failure: NULL if the buffer would overflow. The
- * buffer has as many left-to-right escapes as
- * possible before overflow would have happened.
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_escape(char *s/*in,out*/, size_t size, int escape_spaces)
-{
- size_t n = strlen(s);
- size_t i;
- const char *escape;
- char octal[8];
-
- for (i = 0; i < n; i++) {
- switch (s[i]) {
- case '"':
- escape = "\\\"";
- break;
- case '\\':
- escape = "\\\\";
- break;
- case '\b':
- escape = "\\b";
- break;
- case '\f':
- escape = "\\f";
- break;
- case '\n':
- escape = "\\n";
- break;
- case '\r':
- escape = "\\r";
- break;
- case '\t':
- escape = "\\t";
- break;
- case ' ':
- escape = escape_spaces ? "\\ " : NULL;
- break;
- default:
- if (!isprint((int)*s)) {
- sprintf(octal, "\\%03o", (unsigned char)s[i]);
- escape = octal;
- } else {
- escape = NULL;
- }
-
- break;
- }
-
- if (escape) {
- size_t esc_size = strlen(escape);
-
- if (n + esc_size + 1 > size)
- /*would overflow*/
- return NULL;
-
- memmove(s + i + esc_size, s + i, (n - i) + 1); /*make room*/
- memcpy(s + i, escape, esc_size); /*insert*/
- n += esc_size;
- i += esc_size - 1;
- }
- }
-
- return s;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_is_zero
- *
- * Purpose: Determines if memory is initialized to all zero bytes.
- *
- * Return: TRUE if all bytes are zero; FALSE otherwise
- *
- * Programmer: Robb Matzke
- * Monday, June 7, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hbool_t
-h5dump_is_zero(const void *_mem, size_t size)
-{
- const unsigned char *mem = (const unsigned char *)_mem;
-
- while (size-- > 0)
- if (mem[size])
- return FALSE;
-
- return TRUE;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_region
- *
- * Purpose: Prints information about a dataspace region by appending
- * the information to the specified string.
- *
- * Return: Success: 0
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Monday, June 7, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/, const h5dump_t *info)
-{
- hssize_t nblocks, npoints;
- hsize_t alloc_size;
- hsize_t *ptdata;
- int ndims = H5Sget_simple_extent_ndims(region);
-
- /*
- * These two functions fail if the region does not have blocks or points,
- * respectively. They do not currently know how to translate from one to
- * the other.
- */
- H5E_BEGIN_TRY {
- nblocks = H5Sget_select_hyper_nblocks(region);
- npoints = H5Sget_select_elem_npoints(region);
- } H5E_END_TRY;
-
- h5dump_str_append(str, "{");
-
- /* Print block information */
- if (nblocks > 0) {
- int i;
-
- alloc_size=nblocks * ndims * 2 * sizeof(ptdata[0]);
- assert(alloc_size==(hsize_t)((size_t)alloc_size)); /*check for overflow*/
- ptdata = malloc((size_t)alloc_size);
- H5_CHECK_OVERFLOW(nblocks,hssize_t,hsize_t);
- H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata);
-
- for (i = 0; i < nblocks; i++) {
- int j;
-
- h5dump_str_append(str, info->dset_blockformat_pre,
- i ? "," OPTIONAL_LINE_BREAK " " : "",
- (unsigned long)i);
-
- /* Start coordinates and opposite corner */
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : "(",
- (unsigned long)ptdata[i * 2 * ndims + j]);
-
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : ")-(",
- (unsigned long)ptdata[i * 2 * ndims + j + ndims]);
-
- h5dump_str_append(str, ")");
- }
- free(ptdata);
- }
-
- /* Print point information */
- if (npoints > 0) {
- int i;
-
- alloc_size=npoints * ndims * sizeof(ptdata[0]);
- assert(alloc_size==(hsize_t)((size_t)alloc_size)); /*check for overflow*/
- ptdata = malloc((size_t)alloc_size);
- H5_CHECK_OVERFLOW(npoints,hssize_t,hsize_t);
- H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata);
-
- for (i = 0; i < npoints; i++) {
- int j;
-
- h5dump_str_append(str, info->dset_ptformat_pre ,
- i ? "," OPTIONAL_LINE_BREAK " " : "",
- (unsigned long)i);
-
- for (j = 0; j < ndims; j++)
- h5dump_str_append(str, "%s%lu", j ? "," : "(",
- (unsigned long)(ptdata[i * ndims + j]));
-
- h5dump_str_append(str, ")");
- }
-
- free(ptdata);
- }
-
- h5dump_str_append(str, "}");
- return 0;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_sprint
- *
- * Purpose: Renders the value pointed to by VP of type TYPE into variable
- * length string STR.
- *
- * Return: A pointer to memory containing the result or NULL on error.
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-04-26
- * Made this function safe from overflow problems by allowing it
- * to reallocate the output string.
- *
- * Robb Matzke, 1999-06-04
- * Added support for object references. The new `container'
- * argument is the dataset where the reference came from.
- *
- * Robb Matzke, 1999-06-07
- * Added support for printing raw data. If info->raw is non-zero
- * then data is printed in hexadecimal format.
- *
- *-------------------------------------------------------------------------
- */
-static char *
-h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
- hid_t container, hid_t type, void *vp, h5dump_context_t *ctx)
-{
- size_t n, offset, size, nelmts, start;
- char *name, quote='\0';
- unsigned char *ucp_vp = (unsigned char *)vp;
- char *cp_vp = (char *)vp;
- hid_t memb, obj, region;
- int nmembs, otype;
- static char fmt_llong[8], fmt_ullong[8];
- H5T_str_t pad;
- H5G_stat_t sb;
-
- /*some tempvars to store the value before we append it to the string
- to get rid of the memory alignment problem*/
- float tempfloat;
- double tempdouble;
- int tempint;
- unsigned int tempuint;
- short tempshort;
- unsigned short tempushort;
- long templong;
- unsigned long tempulong;
- unsigned long_long tempullong;
- long_long templlong;
-
- /* Build default formats for long long types */
- if (!fmt_llong[0]) {
- sprintf(fmt_llong, "%%%sd", PRINTF_LL_WIDTH);
- sprintf(fmt_ullong, "%%%su", PRINTF_LL_WIDTH);
- }
-
- /* Append value depending on data type */
- start = h5dump_str_len(str);
-
- if (info->raw) {
- unsigned int i;
-
- h5dump_str_append(str, "0x");
- n = H5Tget_size(type);
-
- for (i = 0; i < n; i++)
- h5dump_str_append(str, OPT(info->fmt_raw, "%02x"), ucp_vp[i]);
- } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
- memcpy(&tempfloat, vp, sizeof(float));
- h5dump_str_append(str, OPT(info->fmt_float, "%g"), tempfloat);
- } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
- memcpy(&tempdouble, vp, sizeof(double));
- h5dump_str_append(str, OPT(info->fmt_double, "%g"), tempdouble);
- } else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) ||
- H5Tequal(type, H5T_NATIVE_UCHAR))) {
- if (ESCAPE_HTML == info->str_locale) {
- if (*cp_vp <= ' ' || *cp_vp > '~')
- h5dump_str_append(str, "%%%02X", *ucp_vp);
- else
- h5dump_str_append(str, "%c", *cp_vp);
- } else {
- switch (*cp_vp) {
- case '"':
- h5dump_str_append(str, "\\\"");
- break;
- case '\\':
- h5dump_str_append(str, "\\\\");
- break;
- case '\b':
- h5dump_str_append(str, "\\b");
- break;
- case '\f':
- h5dump_str_append(str, "\\f");
- break;
- case '\n':
- h5dump_str_append(str, "\\n");
- break;
- case '\r':
- h5dump_str_append(str, "\\r");
- break;
- case '\t':
- h5dump_str_append(str, "\\t");
- break;
- default:
- if (isprint(*cp_vp))
- h5dump_str_append(str, "%c", *cp_vp);
- else
- h5dump_str_append(str, "\\%03o", *ucp_vp);
- break;
- }
- }
- } else if (H5T_STRING == H5Tget_class(type)) {
- unsigned int i;
-
- size = H5Tget_size(type);
- quote = '\0';
- pad = H5Tget_strpad(type);
-
- for (i=0;
- i < size && (cp_vp[i] != '\0' || pad != H5T_STR_NULLTERM);
- i++) {
- int j = 1;
-
- /*
- * Count how many times the next character repeats. If the
- * threshold is zero then that means it can repeat any number
- * of times.
- */
- if (info->str_repeat > 0)
- while (i + j < size && cp_vp[i] == cp_vp[i + j])
- j++;
-
- /*
- * Print the opening quote. If the repeat count is high enough to
- * warrant printing the number of repeats instead of enumerating
- * the characters, then make sure the character to be repeated is
- * in it's own quote.
- */
- if (info->str_repeat > 0 && j > info->str_repeat) {
- if (quote)
- h5dump_str_append(str, "%c", quote);
-
- quote = '\'';
- h5dump_str_append(str, "%s%c", i ? " " : "", quote);
- } else if (!quote) {
- quote = '"';
- h5dump_str_append(str, "%s%c", i ? " " : "", quote);
- }
-
- /* Print the character */
- if (ESCAPE_HTML == info->str_locale) {
- if (cp_vp[i] <= ' ' || cp_vp[i] > '~') {
- h5dump_str_append(str, "%%%02X", ucp_vp[i]);
- } else {
- h5dump_str_append(str, "%c", cp_vp[i]);
- }
- } else {
- switch (cp_vp[i]) {
- case '"':
- h5dump_str_append(str, "\\\"");
- break;
- case '\\':
- h5dump_str_append(str, "\\\\");
- break;
- case '\b':
- h5dump_str_append(str, "\\b");
- break;
- case '\f':
- h5dump_str_append(str, "\\f");
- break;
- case '\n':
- h5dump_str_append(str, "\\n");
- break;
- case '\r':
- h5dump_str_append(str, "\\r");
- break;
- case '\t':
- h5dump_str_append(str, "\\t");
- break;
- default:
- if (isprint(cp_vp[i]))
- h5dump_str_append(str, "%c", cp_vp[i]);
- else
- h5dump_str_append(str, "\\%03o", ucp_vp[i]);
- break;
- }
- }
-
- /* Print the repeat count */
- if (info->str_repeat && j > info->str_repeat) {
-#ifdef REPEAT_VERBOSE
- h5dump_str_append(str, "%c repeats %d times", quote, j - 1);
-#else
- h5dump_str_append(str, "%c*%d", quote, j - 1);
-#endif
- quote = '\0';
- i += j - 1;
- }
-
- }
-
- if (quote)
- h5dump_str_append(str, "%c", quote);
-
- if (0 == i)
- h5dump_str_append(str, "\"\""); /*empty string*/
- } else if (H5Tequal(type, H5T_NATIVE_INT)) {
- memcpy(&tempint, vp, sizeof(int));
- h5dump_str_append(str, OPT(info->fmt_int, "%d"), tempint);
- } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
- memcpy(&tempuint, vp, sizeof(unsigned int));
- h5dump_str_append(str, OPT(info->fmt_uint, "%u"), tempuint);
- } else if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
- h5dump_str_append(str, OPT(info->fmt_schar, "%d"), *((signed char*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
- h5dump_str_append(str, OPT(info->fmt_uchar, "%u"), *((unsigned char*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
- memcpy(&tempshort, vp, sizeof(short));
- h5dump_str_append(str, OPT(info->fmt_short, "%d"), tempshort);
- } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
- memcpy(&tempushort, vp, sizeof(unsigned short));
- h5dump_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort);
- } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
- memcpy(&templong, vp, sizeof(long));
- h5dump_str_append(str, OPT(info->fmt_long, "%ld"), templong);
- } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
- memcpy(&tempulong, vp, sizeof(unsigned long));
- h5dump_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong);
- } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
- memcpy(&templlong, vp, sizeof(long_long));
- h5dump_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong);
- } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
- memcpy(&tempullong, vp, sizeof(unsigned long_long));
- h5dump_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong);
- } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) {
- if (sizeof(hssize_t) == sizeof(int)) {
- memcpy(&tempint, vp, sizeof(int));
- h5dump_str_append(str, OPT(info->fmt_int, "%d"), tempint);
- } else if (sizeof(hssize_t) == sizeof(long)) {
- memcpy(&templong, vp, sizeof(long));
- h5dump_str_append(str, OPT(info->fmt_long, "%ld"), templong);
- } else {
- memcpy(&templlong, vp, sizeof(long_long));
- h5dump_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong);
- }
- } else if (H5Tequal(type, H5T_NATIVE_HSIZE)) {
- if (sizeof(hsize_t) == sizeof(int)) {
- memcpy(&tempuint, vp, sizeof(unsigned int));
- h5dump_str_append(str, OPT(info->fmt_uint, "%u"), tempuint);
- } else if (sizeof(hsize_t) == sizeof(long)) {
- memcpy(&tempulong, vp, sizeof(long));
- h5dump_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong);
- } else {
- memcpy(&tempullong, vp, sizeof(unsigned long_long));
- h5dump_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong);
- }
- } else if (H5T_COMPOUND==H5Tget_class(type)) {
- int j, x;
-
- nmembs = H5Tget_nmembers(type);
- h5dump_str_append(str, "%s", OPT(info->cmpd_pre, "{"));
-
- for (j = 0; j < nmembs; j++) {
- if (j)
- h5dump_str_append(str, "%s", OPT(info->cmpd_sep, ", " OPTIONAL_LINE_BREAK));
-
- /* RPM 2000-10-31
- * If the previous character is a line-feed (which is true when
- * h5dump is running) then insert some white space for
- * indentation. Be warned that column number calculations will be
- * incorrect and that object indices at the beginning of the line
- * will be missing (h5dump doesn't display them anyway). */
- if (ctx->indent_level >= 0 && str->len &&
- str->s[str->len - 1] == '\n') {
- h5dump_str_append(str, OPT(info->line_pre, ""), "");
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5dump_str_append(str, "%s", OPT(info->line_indent, ""));
- }
-
- /* The name */
- name = H5Tget_member_name(type, j);
- h5dump_str_append(str, OPT(info->cmpd_name, ""), name);
- free(name);
-
- /* The value */
- offset = H5Tget_member_offset(type, j);
- memb = H5Tget_member_type(type, j);
-
- ctx->indent_level++;
- h5dump_sprint(str, info, container, memb, cp_vp + offset , ctx);
- ctx->indent_level--;
-
- H5Tclose(memb);
- }
-
- /* RPM 2000-10-31
- * If the previous character is a line feed (which is true when
- * h5dump is running) then insert some white space for indentation.
- * Be warned that column number calculations will be incorrect and
- * that object indices at the beginning of the line will be missing
- * (h5dump doesn't display them anyway). */
- h5dump_str_append(str, "%s", OPT(info->cmpd_end, ""));
-
- if (ctx->indent_level >= 0 && str->len &&
- str->s[str->len - 1] == '\n') {
- h5dump_str_append(str, OPT(info->line_pre, ""), "");
-
- for (x = 0; x < ctx->indent_level; x++)
- h5dump_str_append(str, "%s", OPT(info->line_indent, ""));
- }
-
- h5dump_str_append(str, "%s", OPT(info->cmpd_suf, "}"));
- } else if (H5T_ENUM==H5Tget_class(type)) {
- char enum_name[1024];
-
- if (H5Tenum_nameof(type, vp, enum_name, sizeof enum_name) >= 0) {
- h5dump_str_append(str, h5dump_escape(enum_name, sizeof(enum_name), TRUE));
- } else {
- unsigned int i;
-
- h5dump_str_append(str, "0x");
- n = H5Tget_size(type);
-
- for (i = 0; i < n; i++)
- h5dump_str_append(str, "%02x", ucp_vp[i]);
- }
- } else if (H5Tequal(type, H5T_STD_REF_DSETREG)) {
- /*
- * Dataset region reference -- show the type and OID of the referenced
- * object, but we are unable to show the region yet because there
- * isn't enough support in the data space layer. - rpm 19990604
- */
- if (h5dump_is_zero(vp, H5Tget_size(type))) {
- h5dump_str_append(str, "NULL");
- } else {
- obj = H5Rdereference(container, H5R_DATASET_REGION, vp);
- region = H5Rget_region(container, H5R_DATASET_REGION, vp);
- H5Gget_objinfo(obj, ".", FALSE, &sb);
-
- if (info->dset_hidefileno)
- h5dump_str_append(str, info->dset_format, sb.objno[1], sb.objno[0]);
- else
- h5dump_str_append(str, info->dset_format,
- sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
-
- h5dump_region(region, str, info);
- H5Sclose(region);
- H5Dclose(obj);
- }
- } else if (H5Tequal(type, H5T_STD_REF_OBJ)) {
- /*
- * Object references -- show the type and OID of the referenced
- * object.
- */
- if (h5dump_is_zero(vp, H5Tget_size(type))) {
- h5dump_str_append(str, "NULL");
- } else {
- otype = H5Rget_object_type(container, vp);
- obj = H5Rdereference(container, H5R_OBJECT, vp);
- H5Gget_objinfo(obj, ".", FALSE, &sb);
-
- /* Print object type and close object */
- switch (otype) {
- case H5G_GROUP:
- h5dump_str_append(str, GROUPNAME);
- H5Gclose(obj);
- break;
- case H5G_DATASET:
- h5dump_str_append(str, DATASET);
- H5Dclose(obj);
- break;
- case H5G_TYPE:
- h5dump_str_append(str, DATATYPE);
- H5Tclose(obj);
- break;
- default:
- h5dump_str_append(str, "%u-", otype);
- break;
- }
-
- /* Print OID */
- if (info->obj_hidefileno) {
- h5dump_str_append(str, info->obj_format, sb.objno[1], sb.objno[0]);
- } else {
- h5dump_str_append(str, info->obj_format,
- sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]);
- }
- }
- } else if (H5T_ARRAY==H5Tget_class(type)) {
- int x;
- unsigned int i;
- int k;
- hsize_t dims[H5S_MAX_RANK];
- int ndims;
-
- /* Get the array's base datatype for each element */
- memb=H5Tget_super(type);
-
- size = H5Tget_size(memb);
- ndims = H5Tget_array_ndims(type);
- H5Tget_array_dims(type, dims, NULL);
- assert(ndims>=1 && ndims<=H5S_MAX_RANK);
-
- /* Calculate the number of array elements */
- for (k = 0, nelmts = 1; k < ndims; k++)
- nelmts *= dims[k];
-
- /* Print the opening bracket */
- h5dump_str_append(str, "%s", OPT(info->arr_pre, "["));
-
- for (i = 0; i < nelmts; i++) {
- if (i)
- h5dump_str_append(str, "%s",
- OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK));
-
- if (info->arr_linebreak && i && 0 == i % dims[ndims - 1]) {
- h5dump_str_append(str, "%s", "\n");
-
- /*need to indent some more here*/
- if (ctx->indent_level >= 0)
- h5dump_str_append(str, "%s", OPT(info->line_pre, ""));
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5dump_str_append(str,"%s",OPT(info->line_indent,""));
- } /* end if */
-
- ctx->indent_level++;
-
- /* Dump the array element */
- h5dump_sprint(str, info, container, memb, cp_vp + i * size, ctx);
-
- ctx->indent_level--;
- } /* end for */
-
- /* Print the closing bracket */
- h5dump_str_append(str, "%s", OPT(info->arr_suf, "]"));
-
- H5Tclose(memb);
- } else if (H5T_VLEN==H5Tget_class(type)) {
- unsigned int i;
-
- /* Get the VL sequences's base datatype for each element */
- memb=H5Tget_super(type);
- size = H5Tget_size(memb);
-
- /* Print the opening bracket */
- h5dump_str_append(str, "%s", OPT(info->vlen_pre, "("));
-
- /* Get the number of sequence elements */
- nelmts = ((hvl_t *)cp_vp)->len;
-
- for (i = 0; i < nelmts; i++) {
- if (i)
- h5dump_str_append(str, "%s",
- OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK));
-
-#ifdef LATER
-/* Need to fix so VL data breaks at correct location on end of line -QAK */
- if (info->arr_linebreak && h5dump_str_len(str)>=info->line_ncols) {
- int x;
-
- h5dump_str_append(str, "%s", "\n");
-
- /* need to indent some more here */
- if (ctx->indent_level >= 0)
- h5dump_str_append(str, "%s", OPT(info->line_pre, ""));
-
- for (x = 0; x < ctx->indent_level + 1; x++)
- h5dump_str_append(str,"%s",OPT(info->line_indent,""));
- } /* end if */
-#endif /* LATER */
-
- ctx->indent_level++;
-
- /* Dump the array element */
- h5dump_sprint(str, info, container, memb, ((char *)(((hvl_t *)cp_vp)->p)) + i * size, ctx);
-
- ctx->indent_level--;
- } /* end for */
-
- h5dump_str_append(str, "%s", OPT(info->vlen_suf, ")"));
-
- H5Tclose(memb);
-
- } else {
- /* All other types get printed as hexadecimal */
- unsigned int i;
-
- h5dump_str_append(str, "0x");
- n = H5Tget_size(type);
-
- for (i = 0; i < n; i++)
- h5dump_str_append(str, "%02x", ((unsigned char *)vp)[i]);
- }
-
- return h5dump_str_fmt(str, start, OPT(info->elmt_fmt, "%s"));
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_ncols
- *
- * Purpose: Count the number of columns in a string. This is the number
- * of characters in the string not counting line-control
- * characters.
- *
- * Return: Success: Width of string.
- *
- * Failure: 0
- *
- * Programmer: Robb Matzke
- * Tuesday, April 27, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static size_t
-h5dump_ncols(const char *s)
-{
- size_t i;
-
- for (i = 0; *s; s++)
- if (*s >= ' ')
- i++;
-
- return i;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_simple_prefix
- *
- * Purpose: If ctx->need_prefix is set then terminate the current line
- * (if applicable), calculate the prefix string, and display it
- * at the start of a line.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- * Robb Matzke, 1999-09-29
- * If a new prefix is printed then the current element number is
- * set back to zero.
- *-------------------------------------------------------------------------
- */
-static void
-h5dump_simple_prefix(FILE *stream, const h5dump_t *info,
- h5dump_context_t *ctx, hsize_t elmtno, int secnum)
-{
- h5dump_str_t prefix;
- size_t templength = 0;
- int i, indentlevel = 0;
-
- memset(&prefix, 0, sizeof(h5dump_str_t));
-
- if (!ctx->need_prefix)
- return;
-
- /* Terminate previous line, if any */
- if (ctx->cur_column) {
- fputs(OPT(info->line_suf, ""), stream);
-#if 0 /*why?*/
- if (info->line_ncols != ctx->cur_column) {
- putc('\n', stream);
- }
-#endif
- putc('\n',stream);
- fputs(OPT(info->line_sep, ""), stream);
- }
-
- /* Calculate new prefix */
- h5dump_prefix(&prefix, info, elmtno, ctx->ndims,
- ctx->p_min_idx, ctx->p_max_idx);
-
- /* Write new prefix to output */
- if (ctx->indent_level >= 0) {
- indentlevel = ctx->indent_level;
- } else {
- /* this is because sometimes we dont print out all the header
- * info for the data(like the tattr-2.ddl example. if that happens
- * the ctx->indent_level a negative so we need to skip the above
- * and just print out the default indent levels. */
- indentlevel = ctx->default_indent_level;
- }
-
- if (elmtno == 0 && secnum == 0 && info->line_1st)
- fputs(h5dump_str_fmt(&prefix, 0, info->line_1st), stream);
- else if (secnum && info->line_cont)
- fputs(h5dump_str_fmt(&prefix, 0, info->line_cont), stream);
- else
- fputs(h5dump_str_fmt(&prefix, 0, info->line_pre), stream);
-
- templength = h5dump_str_len(&prefix);
-
- for (i = 0; i < indentlevel; i++){
- fputs(h5dump_str_fmt(&prefix, 0, info->line_indent), stream);
- templength += h5dump_str_len(&prefix);
- }
-
- ctx->cur_column = ctx->prev_prefix_len = templength;
- ctx->cur_elmt = 0;
- ctx->need_prefix = 0;
-
- /* Free string */
- h5dump_str_close(&prefix);
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_simple_data
- *
- * Purpose: Prints some (NELMTS) data elements to output STREAM. The
- * elements are stored in _MEM as type TYPE and are printed
- * according to the format described in INFO. The CTX struct
- * contains context information shared between calls to this
- * function. The FLAGS is a bit field that indicates whether
- * the data supplied in this call falls at the beginning or end
- * of the total data to be printed (START_OF_DATA and
- * END_OF_DATA).
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Monday, April 26, 1999
- *
- * Modifications:
- * Robb Matzke, 1999-06-04
- * The `container' argument is the optional dataset for
- * reference types.
- *
- * Robb Matzke, 1999-09-29
- * Understands the `per_line' property which indicates that
- * every Nth element should begin a new line.
- *
- *-------------------------------------------------------------------------
- */
-static void
-h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
- h5dump_context_t *ctx/*in,out*/, unsigned flags,
- hsize_t nelmts, hid_t type, void *_mem)
-{
- unsigned char *mem = (unsigned char*)_mem;
- hsize_t i; /*element counter */
- char *s, *section; /*a section of output */
- int secnum; /*section sequence number */
- size_t size; /*size of each datum */
- size_t ncols=80; /*available output width */
- h5dump_str_t buffer; /*string into which to render */
- int multiline; /*datum was multiline */
- int elmt_counter=0; /*counts the # elements printed.
- * I (ptl?) needed something that
- * isnt going to get reset when a new
- * line is formed. I'm going to use
- * this var to count elements and
- * break after we see a number equal
- * to the ctx->size_last_dim. */
-
- /* Setup */
- memset(&buffer, 0, sizeof(h5dump_str_t));
- size = H5Tget_size(type);
-
- if (info->line_ncols > 0)
- ncols = info->line_ncols;
-
- h5dump_simple_prefix(stream, info, ctx, (hsize_t)0, 0);
-
- for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) {
- /* Render the element */
- h5dump_str_reset(&buffer);
- h5dump_sprint(&buffer, info, container, type, mem + i * size, ctx);
-
- if (i + 1 < nelmts || 0 == (flags & END_OF_DATA))
- h5dump_str_append(&buffer, "%s", OPT(info->elmt_suf1, ","));
-
- s = h5dump_str_fmt(&buffer, 0, "%s");
-
- /*
- * If the element would split on multiple lines if printed at our
- * current location...
- */
- if (info->line_multi_new == 1 &&
- (ctx->cur_column + h5dump_ncols(s) +
- strlen(OPT(info->elmt_suf2, " ")) +
- strlen(OPT(info->line_suf, ""))) > ncols) {
- if (ctx->prev_multiline) {
- /*
- * ... and the previous element also occupied more than one
- * line, then start this element at the beginning of a line.
- */
- ctx->need_prefix = TRUE;
- } else if ((ctx->prev_prefix_len + h5dump_ncols(s) +
- strlen(OPT(info->elmt_suf2, " ")) +
- strlen(OPT(info->line_suf, ""))) <= ncols) {
- /*
- * ...but *could* fit on one line otherwise, then we
- * should end the current line and start this element on its
- * own line.
- */
- ctx->need_prefix = TRUE;
- }
- }
-
- /*
- * We need to break after each row of a dimension---> we should
- * break at the end of the each last dimension well that is the
- * way the dumper did it before
- */
- if (info->arr_linebreak && ctx->cur_elmt) {
- if (ctx->size_last_dim && (ctx->cur_elmt % ctx->size_last_dim) == 0)
- ctx->need_prefix = TRUE;
-
- if (elmt_counter == ctx->size_last_dim) {
- ctx->need_prefix = TRUE;
- elmt_counter = 0;
- }
- }
-
- /*
- * If the previous element occupied multiple lines and this element
- * is too long to fit on a line then start this element at the
- * beginning of the line.
- */
- if (info->line_multi_new == 1 && ctx->prev_multiline &&
- (ctx->cur_column + h5dump_ncols(s) +
- strlen(OPT(info->elmt_suf2, " ")) +
- strlen(OPT(info->line_suf, ""))) > ncols)
- ctx->need_prefix = TRUE;
-
- /*
- * If too many elements have already been printed then we need to
- * start a new line.
- */
- if (info->line_per_line > 0 && ctx->cur_elmt >= info->line_per_line)
- ctx->need_prefix = TRUE;
-
- /*
- * Each OPTIONAL_LINE_BREAK embedded in the rendered string can cause
- * the data to split across multiple lines. We display the sections
- * one-at a time.
- */
- for (secnum = 0, multiline = 0;
- (section = strtok(secnum ? NULL : s, OPTIONAL_LINE_BREAK));
- secnum++) {
- /*
- * If the current section plus possible suffix and end-of-line
- * information would cause the output to wrap then we need to
- * start a new line.
- */
-
- /*
- * Added the info->skip_first because the dumper does not want
- * this check to happen for the first line
- */
- if ((!info->skip_first || i) &&
- (ctx->cur_column + strlen(section) +
- strlen(OPT(info->elmt_suf2, " ")) +
- strlen(OPT(info->line_suf, ""))) > ncols)
- ctx->need_prefix = 1;
-
- /*
- * Print the prefix or separate the beginning of this element
- * from the previous element.
- */
- if (ctx->need_prefix) {
- if (secnum)
- multiline++;
-
- h5dump_simple_prefix(stream, info, ctx, i, secnum);
- } else if ((i || ctx->continuation) && secnum == 0) {
- fputs(OPT(info->elmt_suf2, " "), stream);
- ctx->cur_column += strlen(OPT(info->elmt_suf2, " "));
- }
-
- /* Print the section */
- fputs(section, stream);
- ctx->cur_column += strlen(section);
- }
-
- ctx->prev_multiline = multiline;
- }
-
- h5dump_str_close(&buffer);
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_simple_dset
- *
- * Purpose: Print some values from a dataset with a simple data space.
- * This is a special case of h5dump_dset(). This function only
- * intended for dumping datasets -- it does strip mining and
- * some other things which are unnecessary for smaller objects
- * such as attributes (to print small objects like attributes
- * simply read the attribute and call h5dump_simple_mem()).
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
- hid_t p_type, int indentlevel)
-{
- hid_t f_space; /*file data space */
- hsize_t elmtno, i; /*counters */
- int carry; /*counter carry value */
- hssize_t zero[8]; /*vector of zeros */
- unsigned flags; /*buffer extent flags */
- hsize_t total_size[H5S_MAX_RANK];/*total size of dataset*/
-
- /* Print info */
- h5dump_context_t ctx; /*print context */
- size_t p_type_nbytes; /*size of memory type */
- hsize_t p_nelmts; /*total selected elmts */
-
- /* Stripmine info */
- hsize_t sm_size[H5S_MAX_RANK]; /*stripmine size */
- hsize_t sm_nbytes; /*bytes per stripmine */
- hsize_t sm_nelmts; /*elements per stripmine*/
- unsigned char *sm_buf=NULL; /*buffer for raw data */
- hid_t sm_space; /*stripmine data space */
-
- /* Hyperslab info */
- hssize_t hs_offset[H5S_MAX_RANK];/*starting offset */
- hsize_t hs_size[H5S_MAX_RANK]; /*size this pass */
- hsize_t hs_nelmts; /*elements in request */
-
- /* VL data special information */
- unsigned vl_data=0; /* Whether the dataset contains VL datatypes */
-
-#if 0
- hsize_t dim_n_size;
-#endif
-
- /*
- * Check that everything looks okay. The dimensionality must not be too
- * great and the dimensionality of the items selected for printing must
- * match the dimensionality of the dataset.
- */
- memset(&ctx, 0, sizeof ctx);
- ctx.indent_level = indentlevel;
- ctx.need_prefix = 1;
- f_space = H5Dget_space(dset);
- ctx.ndims = H5Sget_simple_extent_ndims(f_space);
-
- if ((size_t)ctx.ndims > NELMTS(sm_size))
- return -1;
-
- /* Assume entire data space to be printed */
- if(ctx.ndims>0)
- for (i = 0; i < (hsize_t)ctx.ndims; i++)
- ctx.p_min_idx[i] = 0;
-
- H5Sget_simple_extent_dims(f_space, total_size, NULL);
-
- if(ctx.ndims>0)
- for (i = 0, p_nelmts = 1; i < (hsize_t)ctx.ndims; i++)
- p_nelmts *= total_size[i];
- else
- p_nelmts = 1;
-
- if (p_nelmts == 0) {
- H5Sclose(f_space);
- return 0; /*nothing to print*/
- }
-
- ctx.size_last_dim = total_size[ctx.ndims - 1];
-
- /* Check if we have VL data in the dataset's datatype */
- if(H5Tdetect_class(p_type,H5T_VLEN)==TRUE)
- vl_data=TRUE;
-
- /*
- * Determine the strip mine size and allocate a buffer. The strip mine is
- * a hyperslab whose size is manageable.
- */
- p_type_nbytes = H5Tget_size(p_type);
-
- if(ctx.ndims>0)
- for (i = ctx.ndims, sm_nbytes = p_type_nbytes; i > 0; --i) {
- sm_size[i - 1] = MIN(total_size[i - 1], H5DUMP_BUFSIZE / sm_nbytes);
- sm_nbytes *= sm_size[i - 1];
- assert(sm_nbytes > 0);
- }
- else
- sm_nbytes = p_type_nbytes;
-
- assert(sm_nbytes==(hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
- sm_buf = malloc((size_t)sm_nbytes);
- sm_nelmts = sm_nbytes / p_type_nbytes;
- sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
-
- /* The stripmine loop */
- memset(hs_offset, 0, sizeof hs_offset);
- memset(zero, 0, sizeof zero);
-
- for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) {
- /* Calculate the hyperslab size */
- if (ctx.ndims > 0) {
- for (i = 0, hs_nelmts = 1; i < (hsize_t)ctx.ndims; i++) {
- hs_size[i] = MIN(total_size[i] - hs_offset[i], sm_size[i]);
- ctx.p_max_idx[i] = ctx.p_min_idx[i] + hs_size[i];
- hs_nelmts *= hs_size[i];
- }
-
- H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL,
- hs_size, NULL);
- H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL,
- &hs_nelmts, NULL);
- } else {
- H5Sselect_all(f_space);
- H5Sselect_all(sm_space);
- hs_nelmts = 1;
- }
-
- /* Read the data */
- if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) {
- H5Sclose(f_space);
- H5Sclose(sm_space);
- free(sm_buf);
- return -1;
- }
-
- /* Print the data */
- flags = (elmtno == 0) ? START_OF_DATA : 0;
- flags |= ((elmtno + hs_nelmts) >= p_nelmts) ? END_OF_DATA : 0;
- h5dump_simple_data(stream, info, dset, &ctx, flags, hs_nelmts,
- p_type, sm_buf);
-
- /* Reclaim any VL memory, if necessary */
- if(vl_data)
- H5Dvlen_reclaim(p_type,sm_space,H5P_DEFAULT,sm_buf);
-
- /* Calculate the next hyperslab offset */
- for (i = ctx.ndims, carry = 1; i > 0 && carry; --i) {
- ctx.p_min_idx[i - 1] = ctx.p_max_idx[i - 1];
- hs_offset[i - 1] += hs_size[i - 1];
-
- if (hs_offset[i - 1] == (hssize_t)total_size[i - 1])
- hs_offset[i-1] = 0;
- else
- carry = 0;
- }
-
- ctx.continuation++;
- }
-
- /* Terminate the output */
- if (ctx.cur_column) {
- fputs(OPT(info->line_suf, ""), stream);
- putc('\n', stream);
- fputs(OPT(info->line_sep, ""), stream);
- }
-
- H5Sclose(sm_space);
- H5Sclose(f_space);
- free(sm_buf);
- return 0;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_simple_mem
- *
- * Purpose: Print some values from memory with a simple data space.
- * This is a special case of h5dump_mem().
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type,
- hid_t space, void *mem, int indentlevel)
-{
- hsize_t i; /*counters */
- hsize_t nelmts; /*total selected elmts */
- h5dump_context_t ctx; /*printing context */
-
- /*
- * Check that everything looks okay. The dimensionality must not be too
- * great and the dimensionality of the items selected for printing must
- * match the dimensionality of the dataset.
- */
- memset(&ctx, 0, sizeof(ctx));
- ctx.ndims = H5Sget_simple_extent_ndims(space);
-
- if ((size_t)ctx.ndims > NELMTS(ctx.p_min_idx))
- return -1;
-
- ctx.indent_level = indentlevel;
- ctx.need_prefix = 1;
-
- /* Assume entire data space to be printed */
- for (i = 0; i < (hsize_t)ctx.ndims; i++)
- ctx.p_min_idx[i] = 0;
-
- H5Sget_simple_extent_dims(space, ctx.p_max_idx, NULL);
-
- for (i = 0, nelmts = 1; ctx.ndims != 0 && i < (hsize_t)ctx.ndims; i++)
- nelmts *= ctx.p_max_idx[i] - ctx.p_min_idx[i];
-
- if (nelmts == 0)
- return 0; /*nothing to print*/
-
- ctx.size_last_dim = ctx.p_max_idx[ctx.ndims - 1];
-
- /* Print it */
- h5dump_simple_data(stream, info, obj_id, &ctx,
- START_OF_DATA|END_OF_DATA, nelmts, type, mem);
-
- /* Terminate the output */
- if (ctx.cur_column) {
- fputs(OPT(info->line_suf, ""), stream);
- putc('\n', stream);
- fputs(OPT(info->line_sep, ""), stream);
- }
-
- return 0;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_fixtype
- *
- * Purpose: Given a file data type choose a memory data type which is
- * appropriate for printing the data.
- *
- * Return: Success: Memory data type
- *
- * Failure: FAIL
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-06-04
- * Added support for references.
- *
- *-------------------------------------------------------------------------
- */
-
-hid_t
-h5dump_fixtype(hid_t f_type)
-{
- hid_t m_type = FAIL, f_memb;
- hid_t *memb = NULL;
- char **name = NULL;
- int nmembs = 0, i;
- int ndims;
- hsize_t dim[H5S_MAX_RANK];
- size_t size, offset;
- hid_t array_base;
- /* H5T_str_t strpad; */
-
- size = H5Tget_size(f_type);
-
- switch (H5Tget_class(f_type)) {
- case H5T_INTEGER:
- /*
- * Use the smallest native integer type of the same sign as the file
- * such that the memory type is at least as large as the file type.
- * If there is no memory type large enough then use the largest
- * memory type available.
- */
- if (size <= sizeof(char)) {
- m_type = H5Tcopy(H5T_NATIVE_SCHAR);
- } else if (size <= sizeof(short)) {
- m_type = H5Tcopy(H5T_NATIVE_SHORT);
- } else if (size <= sizeof(int)) {
- m_type = H5Tcopy(H5T_NATIVE_INT);
- } else if (size <= sizeof(long)) {
- m_type = H5Tcopy(H5T_NATIVE_LONG);
- } else {
- m_type = H5Tcopy(H5T_NATIVE_LLONG);
- }
-
- H5Tset_sign(m_type, H5Tget_sign(f_type));
- break;
-
- case H5T_FLOAT:
- /*
- * Use the smallest native floating point type available such that
- * its size is at least as large as the file type. If there is not
- * native type large enough then use the largest native type.
- */
- if (size <= sizeof(float)) {
- m_type = H5Tcopy(H5T_NATIVE_FLOAT);
- } else if (size <= sizeof(double)) {
- m_type = H5Tcopy(H5T_NATIVE_DOUBLE);
- } else {
- m_type = H5Tcopy(H5T_NATIVE_LDOUBLE);
- }
-
- break;
-
- case H5T_STRING:
- /*
- * This is needed because the function in dumputil.c is the case where
- * strDUAction == TRUE. if it is false we will do the original action
- * here.
- */
- m_type = H5Tcopy(f_type);
- H5Tset_cset(m_type, H5T_CSET_ASCII);
- break;
-
- case H5T_COMPOUND:
- /*
- * We have to do this in two steps. The first step scans the file
- * type and converts the members to native types and remembers all
- * their names and sizes, computing the size of the memory compound
- * type at the same time. Then we create the memory compound type
- * and add the members.
- */
- nmembs = H5Tget_nmembers(f_type);
- assert(nmembs>0);
- memb = calloc((size_t)nmembs, sizeof(hid_t));
- name = calloc((size_t)nmembs, sizeof(char *));
-
- for (i = 0, size = 0; i < nmembs; i++) {
-
- /* Get the member type and fix it */
- f_memb = H5Tget_member_type(f_type, i);
- memb[i] = h5dump_fixtype(f_memb);
- H5Tclose(f_memb);
-
- if (memb[i] < 0)
- goto done;
-
- /* Get the member name */
- name[i] = H5Tget_member_name(f_type, i);
-
- if (name[i] == NULL)
- goto done;
-
- /*
- * Compute the new offset so each member is aligned on a byte
- * boundary which is the same as the member size.
- */
- size = ALIGN(size, H5Tget_size(memb[i])) + H5Tget_size(memb[i]);
- }
-
- m_type = H5Tcreate(H5T_COMPOUND, size);
-
- for (i = 0, offset = 0; i < nmembs; i++) {
- if (offset)
- offset = ALIGN(offset, H5Tget_size(memb[i]));
-
- H5Tinsert(m_type, name[i], offset, memb[i]);
- offset += H5Tget_size(memb[i]);
- }
-
- break;
-
- case H5T_ARRAY:
- /* Get the array information */
- ndims = H5Tget_array_ndims(f_type);
- H5Tget_array_dims(f_type, dim, NULL);
-
- /* Get the array's base type and convert it to the printable version */
- f_memb = H5Tget_super(f_type);
- array_base = h5dump_fixtype(f_memb);
-
- /* Copy the array */
- m_type = H5Tarray_create(array_base, ndims, dim, NULL);
-
- /* Close the temporary datatypes */
- H5Tclose(array_base);
- H5Tclose(f_memb);
- break;
-
- case H5T_VLEN:
- /* Get the VL sequence's base type and convert it to the printable version */
- f_memb = H5Tget_super(f_type);
- array_base = h5dump_fixtype(f_memb);
-
- /* Copy the VL type */
- m_type = H5Tvlen_create(array_base);
-
- /* Close the temporary datatypes */
- H5Tclose(array_base);
- H5Tclose(f_memb);
- break;
-
- case H5T_ENUM:
- case H5T_REFERENCE:
- case H5T_OPAQUE:
- /* Same as file type */
- m_type = H5Tcopy(f_type);
- break;
-
- case H5T_BITFIELD:
- /*
- * Same as the file except the offset is set to zero and the byte
- * order is set to little endian.
- */
- m_type = H5Tcopy(f_type);
- H5Tset_offset(m_type, 0);
- H5Tset_order(m_type, H5T_ORDER_LE);
- break;
-
- case H5T_TIME:
- /*
- * These type classes are not implemented yet.
- */
- break;
-
- default:
- /* What the heck? */
- break;
- }
-
- done:
- /* Clean up temp buffers */
- if (memb && name) {
- int j;
-
- for (j = 0; j < nmembs; j++) {
- if (memb[j] >= 0)
- H5Tclose(memb[j]);
-
- if (name[j])
- free(name[j]);
- }
-
- free(memb);
- free(name);
- }
-
- return m_type;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_dset
- *
- * Purpose: Print some values from a dataset DSET to the file STREAM
- * after converting all types to P_TYPE (which should be a
- * native type). If P_TYPE is a negative value then it will be
- * computed from the dataset type using only native types.
- *
- * Note: This function is intended only for datasets since it does
- * some things like strip mining which are unnecessary for
- * smaller objects such as attributes. The easiest way to print
- * small objects is to read the object into memory and call
- * h5dump_mem().
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- * Robb Matzke, 1999-06-07
- * If info->raw is set then the memory datatype will be the same
- * as the file datatype.
- *
- *-------------------------------------------------------------------------
- */
-int
-h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type,
- int indentlevel)
-{
- hid_t f_space;
- hid_t p_type = _p_type;
- hid_t f_type;
- int status = -1;
- h5dump_t info_dflt;
-
- /* Use default values */
- if (!stream)
- stream = stdout;
-
- if (!info) {
- memset(&info_dflt, 0, sizeof info_dflt);
- info = &info_dflt;
- }
-
- if (p_type < 0) {
- f_type = H5Dget_type(dset);
-
- if (info->raw)
- p_type = H5Tcopy(f_type);
- else
- p_type = h5dump_fixtype(f_type);
-
- H5Tclose(f_type);
-
- if (p_type < 0)
- goto done;
- }
-
- /* Check the data space */
- f_space = H5Dget_space(dset);
-
- /* Print the data */
- if (H5Sis_simple(f_space) > 0) {
- status = h5dump_simple_dset(rawdatastream, info, dset, p_type,
- indentlevel);
- }
-
- /* Close the dataspace */
- H5Sclose(f_space);
-
-done:
- if (p_type != _p_type)
- H5Tclose(p_type);
-
- return status;
-}
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_mem
- *
- * Purpose: Displays the data contained in MEM. MEM must have the
- * specified data TYPE and SPACE. Currently only simple data
- * spaces are allowed and only the `all' selection.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Wednesday, January 20, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-h5dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, hid_t space,
- void *mem,int indentlevel)
-{
- h5dump_t info_dflt;
-
- /* Use default values */
- if (!stream)
- stream = stdout;
-
- if (!info) {
- memset(&info_dflt, 0, sizeof info_dflt);
- info = &info_dflt;
- }
-
- /* Check the data space */
- if (H5Sis_simple(space) <= 0)
- return -1;
-
- return h5dump_simple_mem(stream, info, obj_id, type, space, mem, indentlevel);
-}
-
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-
-/*from h5dumputil.c*/
-
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-/*************************************************************************/
-
-/*-------------------------------------------------------------------------
- * Function: indentation
- *
- * Purpose: Print spaces for indentation
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void indentation(int x)
-{
- if (x < nCols) {
- while (x-- > 0)
- printf(" ");
- } else {
- printf("The indentation exceeds the number of cols. Exiting....\n");
- exit(1);
- }
-}
-
-/*-------------------------------------------------------------------------
- * Function: print_version
- *
- * Purpose: Print the program name and the version information which is
- * defined the same as the HDF5 library version.
- *
- * Return: void
- *
- * Programmer: unknown
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void
-print_version(const char *program_name)
-{
- printf("%s: Version %u.%u.%u%s%s\n",
- program_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE,
- H5_VERS_SUBRELEASE[0] ? "-" : "", H5_VERS_SUBRELEASE);
-}
-
-/*
- *
- * THE FUNCTIONS BELOW ARE FROM THE H5FINSHD.C FILE
- *
- */
-
-/*-------------------------------------------------------------------------
- * Function: init_table
- *
- * Purpose: allocate and initialize tables for shared groups, datasets,
- * and committed types
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void
-init_table(table_t** temp)
-{
- int i;
- table_t *table = malloc(sizeof(table_t));
-
- table->size = 20;
- table->nobjs = 0;
- table->objs = (obj_t*) malloc(table->size*sizeof(obj_t));
-
- for (i = 0; i < table->size; i++) {
- table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
- table->objs[i].displayed = 0;
- table->objs[i].recorded = 0;
- table->objs[i].objflag = 0;
- }
-
- *temp = table;
-}
-
-/*-------------------------------------------------------------------------
- * Function: init_prefix
- *
- * Purpose: allocate and initialize prefix
- *
- * Return: void
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void
-init_prefix(char **prefix, int prefix_len)
-{
- assert(prefix_len > 0);
- *prefix = calloc((size_t)prefix_len, 1);
-}
-
-/*-------------------------------------------------------------------------
- * Function: free_table
- *
- * Purpose: free tables for shared groups, datasets,
- * and committed types
- *
- * Return: void
- *
- * Programmer: Paul Harten
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void
-free_table(table_t **table)
-{
- HDfree((*table)->objs);
-}
-
-/*-------------------------------------------------------------------------
- * Function: search_obj
- *
- * Purpose: search the object specified by objno in the table
- *
- * Return: an integer, the location of the object
- * -1 if object is not found
- *
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-int
-search_obj(table_t *table, unsigned long *objno)
-{
- int i;
-
- for (i = 0; i < table->nobjs; i++)
- if (table->objs[i].objno[0] == *objno && table->objs[i].objno[1] == *(objno + 1))
- return i;
-
- return -1;
-}
-
-/*-------------------------------------------------------------------------
- * Function: add_obj
- *
- * Purpose: add a shared object to the table
- * realloc the table if necessary
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static void
-add_obj (table_t *table, unsigned long *objno, char *objname)
-{
- int i;
-
- if (table->nobjs == table->size) {
- table->size *= 2;
- table->objs = realloc(table->objs, table->size*sizeof(obj_t));
-
- for (i = table->nobjs; i < table->size; i++) {
- table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
- table->objs[i].displayed = 0;
- table->objs[i].recorded = 0;
- table->objs[i].objflag = 0;
- }
- }
-
- i = table->nobjs++;
- table->objs[i].objno[0] = *objno;
- table->objs[i].objno[1] = *(objno + 1);
- strcpy(table->objs[i].objname, objname);
-}
-
-/*-------------------------------------------------------------------------
- * Function: Find_objs
- *
- * Purpose: Find objects, committed types and store them in tables
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-herr_t
-find_objs(hid_t group, const char *name, void *op_data)
-{
- hid_t obj, type;
- H5G_stat_t statbuf;
- char *tmp;
- int i;
- find_objs_t *info = (find_objs_t*)op_data;
-
- if (info->threshold > 1)
- /*will get an infinite loop if greater than 1*/
- return FAIL;
-
- H5Gget_objinfo(group, name, TRUE, &statbuf);
-
- tmp = malloc(strlen(info->prefix) + strlen(name) + 2);
- strcpy(tmp, info->prefix);
-
- switch (statbuf.type) {
- case H5G_GROUP:
- if ((obj = H5Gopen(group, name)) >= 0) {
- if (info->prefix_len < (int)(strlen(info->prefix) + strlen(name) + 2)) {
- info->prefix_len *= 2;
- info->prefix = realloc(info->prefix,
- info->prefix_len * sizeof(char));
- }
-
- strcat(strcat(info->prefix,"/"), name);
-
- if (statbuf.nlink > info->threshold) {
- if (search_obj(info->group_table, statbuf.objno) < 0) {
- add_obj(info->group_table, statbuf.objno, info->prefix);
- H5Giterate(obj, ".", NULL, find_objs, (void *)info);
- }
- } else {
- H5Giterate (obj, ".", NULL, find_objs, (void *)info);
- }
-
- strcpy(info->prefix, tmp);
- H5Gclose (obj);
- } else {
- info->status = 1;
- }
-
- break;
-
- case H5G_DATASET:
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the data set */
-
- if (statbuf.nlink > info->threshold &&
- search_obj(info->dset_table, statbuf.objno) < 0)
- add_obj(info->dset_table, statbuf.objno, tmp);
-
- if ((obj = H5Dopen (group, name)) >= 0) {
- type = H5Dget_type(obj);
-
- if (H5Tcommitted(type) > 0) {
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
-
- if (search_obj (info->type_table, statbuf.objno) < 0) {
- add_obj(info->type_table, statbuf.objno, tmp);
- info->type_table->objs[info->type_table->nobjs - 1].objflag = 0;
- }
- }
-
- H5Tclose(type);
- H5Dclose (obj);
- } else {
- info->status = 1;
- }
-
- break;
-
- case H5G_TYPE:
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the type */
- i = search_obj(info->type_table, statbuf.objno);
-
- if (i < 0) {
- add_obj(info->type_table, statbuf.objno, tmp) ;
-
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].recorded = 1;
-
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
- } else {
- strcpy (info->type_table->objs[i].objname, tmp);
- info->type_table->objs[i].recorded = 1;
-
- /* named data type */
- info->type_table->objs[info->type_table->nobjs-1].objflag = 1;
- }
-
- break;
-
- default:
- break;
- }
-
- free(tmp);
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: dump_tables
- *
- * Purpose: display the contents of tables for debugging purposes
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-void
-dump_table(char* tablename, table_t *table)
-{
- int i;
-
- printf("%s: # of entries = %d\n", tablename,table->nobjs);
-
- for ( i = 0; i < table->nobjs; i++)
- printf("%lu %lu %s %d\n", table->objs[i].objno[0],
- table->objs[i].objno[1],
- table->objs[i].objname,
- table->objs[i].objflag);
-}
-
-/*-------------------------------------------------------------------------
- * Function: get_table_idx
- *
- * Purpose: Determine if objects are in a link loop
- *
- * Return: Success: table index of object detected to be in loop
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- *-----------------------------------------------------------------------*/
-int
-get_table_idx(table_t *table, unsigned long *objno)
-{
- return search_obj(table, objno);
-
-}
-
-/*-------------------------------------------------------------------------
- * Function: Get table flag setting
- *
- * Purpose: Keep the structures and variables used private to
- * this file.
- *
- * Return: Success: Boolean setting of the i'th element of the
- * object table flag
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- *-----------------------------------------------------------------------*/
-int
-get_tableflag(table_t *table, int idx)
-{
- return table->objs[idx].objflag;
-}
-
-/*-------------------------------------------------------------------------
- * Function: Set table flag setting
- *
- * Purpose: Keep the structures and variables used private to
- * this file.
- *
- * Return: Success: Boolean setting of the i'th element of the
- * object table flag
- *
- * Failure: FAIL
- *
- * Programmer: Paul Harten
- *
- *-----------------------------------------------------------------------*/
-int
-set_tableflag(table_t *table, int idx)
-{
- table->objs[idx].objflag = TRUE;
- return SUCCEED;
-}
-
-/*-------------------------------------------------------------------------
- * Function: Get name of i'th object in table
- *
- * Purpose:
- *
- * Return: Success: strdup() of object name character string
- *
- * Failure: NULL
- *
- * Programmer: Paul Harten
- *
- *-----------------------------------------------------------------------*/
-char *
-get_objectname(table_t* table, int idx)
-{
- return strdup(table->objs[idx].objname);
-}
-
-/*-------------------------------------------------------------------------
- * Function: opens a file using the list of drivers
- *
- * Purpose: Attempts to open a file with various VFL drivers.
- *
- * Return: Success: a file id for the opened file. If
- * DRIVERNAME is non-null then the first
- * DRIVERNAME_SIZE-1 characters of the driver
- * name are copied into the DRIVERNAME array
- * and null terminated.
- *
- * Failure: -1. If DRIVERNAME is non-null then the
- * first byte is set to the null terminator.
- *
- * Modifications:
- * Robb Matzke, 2000-06-23
- * We only have to initialize driver[] on the first call,
- * thereby preventing memory leaks from repeated calls to
- * H5Pcreate().
- *
- * Robb Matzke, 2000-06-23
- * Added DRIVERNAME_SIZE arg to prevent overflows when
- * writing to DRIVERNAME.
- *
- * Robb Matzke, 2000-06-23
- * Added test to prevent coredump when the file could not be
- * opened by any driver.
- *
- * Robb Matzke, 2000-06-23
- * Changed name from H5ToolsFopen() so it jives better with
- * the names we already have at the top of this source file.
- *
- * Thomas Radke, 2000-09-12
- * Added Stream VFD to the driver[] array.
- *
- * Bill Wendling, 2001-01-10
- * Changed macro behavior so that if we have a version other
- * than 1.2.x (i.e., > 1.2), then we do the drivers check.
- *-----------------------------------------------------------------------*/
-hid_t
-h5dump_fopen(const char *fname, char *drivername, size_t drivername_size)
-{
- static struct {
- const char *name;
- hid_t fapl;
- } driver[16];
- static int ndrivers = 0;
- hid_t fid=(-1);
-#ifndef VERSION12
- hid_t fapl = H5P_DEFAULT;
-#endif
- int drivernum;
-
- if (!ndrivers) {
- /* Build a list of file access property lists which we should try
- * when opening the file. Eventually we'd like some way for the
- * user to augment/replace this list interactively. */
- driver[ndrivers].name = "sec2";
- driver[ndrivers].fapl = H5P_DEFAULT;
- ndrivers++;
-
-#ifndef VERSION12
- driver[ndrivers].name = "family";
- driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
- H5Pset_fapl_family(fapl, (hsize_t)0, H5P_DEFAULT);
- ndrivers++;
-
- driver[ndrivers].name = "split";
- driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
- H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);
- ndrivers++;
-
- driver[ndrivers].name = "multi";
- driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
- H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE);
- ndrivers++;
-
-#ifdef H5_HAVE_STREAM
- driver[ndrivers].name = "stream";
- driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
- H5Pset_fapl_stream(fapl, NULL);
- ndrivers++;
-#endif /* H5_HAVE_STREAM */
-#endif /* !VERSION12 */
- }
-
- /* Try to open the file using each of the drivers */
- for (drivernum = 0; drivernum < ndrivers; drivernum++) {
- H5E_BEGIN_TRY {
- fid = H5Fopen(fname, H5F_ACC_RDONLY, driver[drivernum].fapl);
- } H5E_END_TRY;
-
- if (fid >= 0)
- break;
- }
-
- /* Save the driver name */
- if (drivername && drivername_size){
- if (fid >= 0) {
- strncpy(drivername, driver[drivernum].name, drivername_size);
- drivername[drivername_size - 1] = '\0';
- } else {
- drivername[0] = '\0'; /*no file opened*/
- }
- }
-
- return fid;
-}
diff --git a/tools/h5tools.h b/tools/h5tools.h
deleted file mode 100644
index 13aaeed..0000000
--- a/tools/h5tools.h
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
- * Copyright © 1998, 1999, 2000, 2001
- * National Center for Supercomputing Applications
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Thursday, July 23, 1998
- *
- * Purpose: Support functions for the various tools.
- */
-#ifndef H5TOOLS_H_
-#define H5TOOLS_H_
-
-#include <hdf5.h>
-#include <stdio.h>
-
-#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 2
-#define VERSION12
-#endif /* H5_VERS_MAJOR == 1 && H5_VERS_MINOR == 2 */
-
-#define ESCAPE_HTML 1
-
-/*
- * Information about how to format output.
- */
-typedef struct h5dump_t {
- /*
- * Fields associated with formatting numeric data. If a datatype matches
- * multiple formats based on its size, then the first applicable format
- * from this list is used. However, if `raw' is non-zero then dump all
- * data in hexadecimal format without translating from what appears on
- * disk.
- *
- * raw: If set then print all data as hexadecimal without
- * performing any conversion from disk.
- *
- * fmt_raw: The printf() format for each byte of raw data. The
- * default is `%02x'.
- *
- * fmt_int: The printf() format to use when rendering data which is
- * typed `int'. The default is `%d'.
- *
- * fmt_uint: The printf() format to use when rendering data which is
- * typed `unsigned'. The default is `%u'.
- *
- * fmt_schar: The printf() format to use when rendering data which is
- * typed `signed char'. The default is `%d'. This format is
- * used ony if the `ascii' field is zero.
- *
- * fmt_uchar: The printf() format to use when rendering data which is
- * typed `unsigned char'. The default is `%u'. This format
- * is used only if the `ascii' field is zero.
- *
- * fmt_short: The printf() format to use when rendering data which is
- * typed `short'. The default is `%d'.
- *
- * fmt_ushort: The printf() format to use when rendering data which is
- * typed `unsigned short'. The default is `%u'.
- *
- * fmt_long: The printf() format to use when rendering data which is
- * typed `long'. The default is `%ld'.
- *
- * fmt_ulong: The printf() format to use when rendering data which is
- * typed `unsigned long'. The default is `%lu'.
- *
- * fmt_llong: The printf() format to use when rendering data which is
- * typed `long long'. The default depends on what printf()
- * format is available to print this datatype.
- *
- * fmt_ullong: The printf() format to use when rendering data which is
- * typed `unsigned long long'. The default depends on what
- * printf() format is available to print this datatype.
- *
- * fmt_double: The printf() format to use when rendering data which is
- * typed `double'. The default is `%g'.
- *
- * fmt_float: The printf() format to use when rendering data which is
- * typed `float'. The default is `%g'.
- *
- * ascii: If set then print 1-byte integer values as an ASCII
- * character (no quotes). If the character is one of the
- * standard C escapes then print the escaped version. If
- * the character is unprintable then print a 3-digit octal
- * escape. If `ascii' is zero then then 1-byte integers are
- * printed as numeric values. The default is zero.
- *
- * str_locale: Determines how strings are printed. If zero then strings
- * are printed like in C except. If set to ESCAPE_HTML then
- * strings are printed using HTML encoding where each
- * character not in the class [a-zA-Z0-9] is substituted
- * with `%XX' where `X' is a hexadecimal digit.
- *
- * str_repeat: If set to non-zero then any character value repeated N
- * or more times is printed as 'C'*N
- *
- * Numeric data is also subject to the formats for individual elements.
- */
- hbool_t raw;
- const char *fmt_raw;
- const char *fmt_int;
- const char *fmt_uint;
- const char *fmt_schar;
- const char *fmt_uchar;
- const char *fmt_short;
- const char *fmt_ushort;
- const char *fmt_long;
- const char *fmt_ulong;
- const char *fmt_llong;
- const char *fmt_ullong;
- const char *fmt_double;
- const char *fmt_float;
- int ascii;
- int str_locale;
- int str_repeat;
-
- /*
- * Fields associated with compound array members.
- *
- * pre: A string to print at the beginning of each array. The
- * default value is the left square bracket `['.
- *
- * sep: A string to print between array values. The default
- * value is a ",\001" ("\001" indicates an optional line
- * break).
- *
- * suf: A string to print at the end of each array. The default
- * value is a right square bracket `]'.
- *
- * linebreaks: a boolean value to determine if we want to break the line
- * after each row of an array.
- */
- const char *arr_pre;
- const char *arr_sep;
- const char *arr_suf;
- int arr_linebreak;
-
- /*
- * Fields associated with compound data types.
- *
- * name: How the name of the struct member is printed in the
- * values. By default the name is not printed, but a
- * reasonable setting might be "%s=" which prints the name
- * followed by an equal sign and then the value.
- *
- * sep: A string that separates one member from another. The
- * default is ", \001" (the \001 indicates an optional
- * line break to allow structs to span multiple lines of
- * output).
- *
- * pre: A string to print at the beginning of a compound type.
- * The default is a left curly brace.
- *
- * suf: A string to print at the end of each compound type. The
- * default is right curly brace.
- *
- * end: a string to print after we reach the last element of
- * each compound type. prints out before the suf.
- */
- const char *cmpd_name;
- const char *cmpd_sep;
- const char *cmpd_pre;
- const char *cmpd_suf;
- const char *cmpd_end;
-
- /*
- * Fields associated with vlen data types.
- *
- * sep: A string that separates one member from another. The
- * default is ", \001" (the \001 indicates an optional
- * line break to allow structs to span multiple lines of
- * output).
- *
- * pre: A string to print at the beginning of a vlen type.
- * The default is a left parentheses.
- *
- * suf: A string to print at the end of each vlen type. The
- * default is a right parentheses.
- *
- * end: a string to print after we reach the last element of
- * each compound type. prints out before the suf.
- */
- const char *vlen_sep;
- const char *vlen_pre;
- const char *vlen_suf;
- const char *vlen_end;
-
- /*
- * Fields associated with the individual elements.
- *
- * fmt: A printf(3c) format to use to print the value string
- * after it has been rendered. The default is "%s".
- *
- * suf1: This string is appended to elements which are followed by
- * another element whether the following element is on the
- * same line or the next line. The default is a comma.
- *
- * suf2: This string is appended (after `suf1') to elements which
- * are followed on the same line by another element. The
- * default is a single space.
- */
- const char *elmt_fmt;
- const char *elmt_suf1;
- const char *elmt_suf2;
-
- /*
- * Fields associated with the index values printed at the left edge of
- * each line of output.
- *
- * n_fmt: Each index value is printed according to this printf(3c)
- * format string which should include a format for a long
- * integer. The default is "%lu".
- *
- * sep: Each integer in the index list will be separated from the
- * others by this string, which defaults to a comma.
- *
- * fmt: After the index values are formated individually and
- * separated from one another by some string, the entire
- * resulting string will be formated according to this
- * printf(3c) format which should include a format for a
- * character string. The default is "%s".
- */
- const char *idx_n_fmt; /*index number format */
- const char *idx_sep; /*separator between numbers */
- const char *idx_fmt; /*entire index format */
-
- /*
- * Fields associated with entire lines.
- *
- * ncols: Number of columns per line defaults to 80.
- *
- * per_line: If this field has a positive value then every Nth element
- * will be printed at the beginning of a line.
- *
- * pre: Each line of output contains an optional prefix area
- * before the data. This area can contain the index for the
- * first datum (represented by `%s') as well as other
- * constant text. The default value is `%s'.
- *
- * 1st: This is the format to print at the beginning of the first
- * line of output. The default value is the current value of
- * `pre' described above.
- *
- * cont: This is the format to print at the beginning of each line
- * which was continued because the line was split onto
- * multiple lines. This often happens with compound
- * data which is longer than one line of output. The default
- * value is the current value of the `pre' field
- * described above.
- *
- * suf: This character string will be appended to each line of
- * output. It should not contain line feeds. The default
- * is the empty string.
- *
- * sep: A character string to be printed after every line feed
- * defaulting to the empty string. It should end with a
- * line feed.
- *
- * multi_new: Indicates the algorithm to use when data elements tend to
- * occupy more than one line of output. The possible values
- * are (zero is the default):
- *
- * 0: No consideration. Each new element is printed
- * beginning where the previous element ended.
- *
- * 1: Print the current element beginning where the
- * previous element left off. But if that would result
- * in the element occupying more than one line and it
- * would only occupy one line if it started at the
- * beginning of a line, then it is printed at the
- * beginning of the next line.
- *
- * multi_new: If an element is continued onto additional lines then
- * should the following element begin on the next line? The
- * default is to start the next element on the same line
- * unless it wouldn't fit.
- *
- * indentlevel: a string that shows how far to indent if extra spacing
- * is needed. dumper uses it.
- */
- int line_ncols; /*columns of output */
- size_t line_per_line; /*max elements per line */
- const char *line_pre; /*prefix at front of each line */
- const char *line_1st; /*alternate pre. on first line */
- const char *line_cont; /*alternate pre. on continuation*/
- const char *line_suf; /*string to append to each line */
- const char *line_sep; /*separates lines */
- int line_multi_new; /*split multi-line outputs? */
- const char *line_indent; /*for extra identation if we need it*/
-
- /*used to skip the first set of checks for line length*/
- int skip_first;
-
- /*flag used to hide or show the file number for obj refs*/
- int obj_hidefileno;
-
- /*string used to format the output for the obje refs*/
- const char *obj_format;
-
- /*flag used to hide or show the file number for dataset regions*/
- int dset_hidefileno;
-
- /*string used to format the output for the dataset regions*/
- const char *dset_format;
-
- const char *dset_blockformat_pre;
- const char *dset_ptformat_pre;
- const char *dset_ptformat;
-
-} h5dump_t;
-
-
-typedef struct dump_header{
- const char *name;
- const char *filebegin;
- const char *fileend;
- const char *bootblockbegin;
- const char *bootblockend;
- const char *groupbegin;
- const char *groupend;
- const char *datasetbegin;
- const char *datasetend;
- const char *attributebegin;
- const char *attributeend;
- const char *datatypebegin;
- const char *datatypeend;
- const char *dataspacebegin;
- const char *dataspaceend;
- const char *databegin;
- const char *dataend;
- const char *softlinkbegin;
- const char *softlinkend;
-
- const char *fileblockbegin;
- const char *fileblockend;
- const char *bootblockblockbegin;
- const char *bootblockblockend;
- const char *groupblockbegin;
- const char *groupblockend;
- const char *datasetblockbegin;
- const char *datasetblockend;
- const char *attributeblockbegin;
- const char *attributeblockend;
- const char *datatypeblockbegin;
- const char *datatypeblockend;
- const char *dataspaceblockbegin;
- const char *dataspaceblockend;
- const char *datablockbegin;
- const char *datablockend;
- const char *softlinkblockbegin;
- const char *softlinkblockend;
- const char *strblockbegin;
- const char *strblockend;
- const char *enumblockbegin;
- const char *enumblockend;
- const char *structblockbegin;
- const char *structblockend;
- const char *vlenblockbegin;
- const char *vlenblockend;
-
- const char *dataspacedescriptionbegin;
- const char *dataspacedescriptionend;
- const char *dataspacedimbegin;
- const char *dataspacedimend;
-
-} dump_header;
-
-/*
- * begin get_option section
- */
-extern int opt_err; /* getoption prints errors if this is on */
-extern int opt_ind; /* token pointer */
-extern const char *opt_arg; /* flag argument (or value) */
-
-enum {
- no_arg = 0, /* doesn't take an argument */
- require_arg, /* requires an argument */
- optional_arg /* argument is optional */
-};
-
-/*
- * get_option determines which options are specified on the command line and
- * returns a pointer to any arguments possibly associated with the option in
- * the ``opt_arg'' variable. get_option returns the shortname equivalent of
- * the option. The long options are specified in the following way:
- *
- * struct long_options foo[] = {
- * { "filename", require_arg, 'f' },
- * { "append", no_arg, 'a' },
- * { "width", require_arg, 'w' },
- * { NULL, 0, 0 }
- * };
- *
- * Long named options can have arguments specified as either:
- *
- * ``--param=arg'' or ``--param arg''
- *
- * Short named options can have arguments specified as either:
- *
- * ``-w80'' or ``-w 80''
- *
- * and can have more than one short named option specified at one time:
- *
- * -aw80
- *
- * in which case those options which expect an argument need to come at the
- * end.
- */
-typedef struct long_options {
- const char *name; /* name of the long option */
- int has_arg; /* whether we should look for an arg */
- char shortval; /* the shortname equivalent of long arg
- * this gets returned from get_option */
-} long_options;
-
-extern int get_option(int argc, const char **argv, const char *opt,
- const struct long_options *l_opt);
-/*
- * end get_option section
- */
-
-extern hid_t h5dump_fixtype(hid_t f_type);
-extern int h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset,
- hid_t p_typ, int indentlevel);
-extern int h5dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id,
- hid_t type, hid_t space, void *mem, int indentlevel);
-extern hid_t h5dump_fopen(const char *fname, char *drivername, size_t drivername_len);
-
-
-/*if we get a new program that needs to use the library add its name here*/
-typedef enum {
- UNKNOWN = 0,
- H5LS,
- H5DUMP
-} ProgType;
-
-/*struct taken from the dumper. needed in table struct*/
-typedef struct obj_t {
- unsigned long objno[2];
- char objname[1024];
- int displayed;
- int recorded;
- int objflag;
-} obj_t;
-
-/*struct for the tables that the find_objs function uses*/
-typedef struct table_t {
- int size;
- int nobjs;
- obj_t *objs;
-} table_t;
-
-/*this struct stores the information that is passed to the find_objs function*/
-typedef struct find_objs_t {
- int prefix_len;
- char *prefix;
- unsigned int threshold; /* should be 0 or 1 */
- table_t *group_table;
- table_t *type_table;
- table_t *dset_table;
- int status;
-} find_objs_t;
-
-extern herr_t find_objs(hid_t group, const char *name, void *op_data);
-extern int search_obj (table_t *temp, unsigned long *);
-extern void init_table(table_t **temp);
-extern void init_prefix(char **temp, int);
-
-/* taken from h5dump.h */
-#define ATTRIBUTE_DATA 0
-#define DATASET_DATA 1
-#define ENUM_DATA 2
-
-#define COL 3
-
-extern int indent; /*how far in to indent the line */
-extern int nCols; /*max number of columns for outputting */
-extern FILE *rawdatastream; /*output stream for raw data */
-
-extern void indentation(int);
-
-/* taken from h5dump.h*/
-#define BOOT_BLOCK "BOOT_BLOCK"
-#define GROUPNAME "GROUP"
-#define DATASET "DATASET"
-#define ATTRIBUTE "ATTRIBUTE"
-#define DATATYPE "DATATYPE"
-#define DATASPACE "DATASPACE"
-#define DATA "DATA"
-#define SCALAR "SCALAR"
-#define SIMPLE "SIMPLE"
-#define COMPLEX "COMPLEX"
-#define STORAGELAYOUT "STORAGELAYOUT"
-#define COMPRESSION "COMPRESSION"
-#define EXTERNAL "EXTERNAL"
-#define SOFTLINK "SOFTLINK"
-#define HARDLINK "HARDLINK"
-#define NLINK "NLINK"
-#define FILENO "FILENO"
-#define OBJNO "OBJNO"
-#define STRSIZE "STRSIZE"
-#define STRPAD "STRPAD"
-#define CSET "CSET"
-#define CTYPE "CTYPE"
-#define CONCATENATOR "//"
-#define DATASET "DATASET"
-#define OBJID "OBJECTID"
-#define BEGIN "{"
-#define END "}"
-
-/* Definitions of useful routines */
-extern void print_version(const char *program_name);
-extern void h5tools_init(void);
-extern void h5tools_close(void);
-
-#endif /* H5TOOLS_H_ */
diff --git a/tools/pdb2hdf.c b/tools/pdb2hdf.c
deleted file mode 100644
index 7ecd28e..0000000
--- a/tools/pdb2hdf.c
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * Copyright © 1999 NCSA
- * All rights reserved.
- *
- * Programmer: Robb Matzke <matzke@llnl.gov>
- * Tuesday, October 12, 1999
- *
- * Purpose: Creates an HDF5 file from a PDB file. The raw data can be
- * left in the PDB file, creating an HDF5 file that contains
- * meta data that points into the PDB file.
- */
-#include <assert.h>
-#include <hdf5.h>
-#include <pdb.h>
-#include <score.h>
-#include <stdio.h>
-#include <string.h>
-
-/*
- * libsilo renames all the PDB functions. However, this source files uses
- * their documented names, so we have #define's to translate them to Silo
- * terminology.
- */
-#ifdef H5_HAVE_LIBSILO
-# define PD_open lite_PD_open
-# define PD_close lite_PD_close
-# define PD_ls lite_PD_ls
-# define PD_cd lite_PD_cd
-# define PD_inquire_entry lite_PD_inquire_entry
-# define PD_read lite_PD_read
-# define _PD_fixname _lite_PD_fixname
-# define _PD_rl_defstr _lite_PD_rl_defstr
-# define SC_free lite_SC_free
-#endif
-
-static int verbose_g = 0; /*verbose output? */
-static int cached_g = 0; /*use core file driver? */
-
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: Print a usage message.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-usage(const char *arg0)
-{
- char *progname;
-
- if ((progname=strrchr(arg0, '/')) && progname[1]) progname++;
- else progname = arg0;
-
- fprintf(stderr, "\
-usage: %s [OPTIONS] [PDBFILE ...]\n\
- OPTIONS\n\
- -h, -?, --help Print a usage message and exit\n\
- -c, --cached Cache all data in memory before writing the output\n\
- -v, --verbose Print the name of each object processed\n\
- -V, --version Show the version number of this program\n\
-\n\
- The options and PDB file names may be interspersed and are processed from\n\
- left to right.\n\
-\n\
- The name of the HDF5 file is generated by taking the basename of the PDB\n\
- file and replacing the last extension (or appending if no extension) with\n\
- the characters \".h5\". For example, \"/tmp/test/eos.data\" would result\n\
- in an HDF5 file called \"eos.h5\" in the current directory.\n",
- progname);
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: version
- *
- * Purpose: Print the version number.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Friday, October 15, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-version(const char *arg0)
-{
- const char *progname;
-
- if ((progname=strrchr(arg0, '/')) && progname[1]) progname++;
- else progname = arg0;
- print_version(progname);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_name
- *
- * Purpose: Given a PDB file name create the corresponding HDF5 file
- * name. This is done by taking the base name of the PDB file
- * and replacing (or appending) the last extension with ".h5".
- *
- * Return: Success: HDF_NAME
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-fix_name(const char *pdb_name, char *hdf_name, size_t size)
-{
- char *s;
- const char *ext;
-
- if (!pdb_name || !hdf_name) return NULL;
- if ((s=strrchr(pdb_name, '/'))) pdb_name = s;
- if (NULL==(ext=strrchr(pdb_name, '.'))) ext = pdb_name + strlen(pdb_name);
- if ((size_t)((ext-pdb_name)+4) > size) return NULL; /*overflow*/
- memcpy(hdf_name, pdb_name, ext-pdb_name);
- strcpy(hdf_name+(ext-pdb_name), ".h5");
- return hdf_name;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_type
- *
- * Purpose: Given a PDB datatype return a corresponding hdf5 datatype.
- * The hdf5 datatype should be closed when the caller is
- * finished using it.
- *
- * Return: Success: HDF5 datatype
- *
- * Failure: negative
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-fix_type(PDBfile *pdb, const char *s)
-{
- hid_t type = -1;
- defstr *d = _lite_PD_lookup_type((char*)s, pdb->chart);
-
- /* PDB checking */
- assert(d);
- assert(d->size>0);
- if (d->onescmp) return -1;
-
-
- if (!strcmp(s, "char")) {
- /*
- * Character datatypes. Use whatever sign the native system uses by
- * default.
- */
- type = H5Tcopy(H5T_NATIVE_CHAR);
-
- } else if (!strcmp(s, "integer")) {
- /*
- * Integer datatypes. PDB supports various sizes of signed or
- * unsigned integers.
- */
- type = H5Tcopy(d->unsgned?H5T_NATIVE_UINT:H5T_NATIVE_INT);
- H5Tset_size(type, d->size);
- H5Tset_precision(type, 8*d->size);
- assert(NORMAL_ORDER==d->order_flag || REVERSE_ORDER==d->order_flag);
- H5Tset_order(type,
- NORMAL_ORDER==d->order_flag?H5T_ORDER_BE:H5T_ORDER_LE);
-
- } else if (!strcmp(s, "float") || !strcmp(s, "double")) {
- /*
- * Floating-point datatypes
- */
- size_t nbits, spos, epos, esize, mpos, msize;
-
- type = H5Tcopy(H5T_NATIVE_FLOAT);
- H5Tset_size(type, d->size);
- H5Tset_precision(type, 8*d->size);
- assert(d->order);
- H5Tset_order(type, 1==d->order[0]?H5T_ORDER_BE:H5T_ORDER_LE);
-
- /*
- * format[0] = # of bits per number
- * format[1] = # of bits in exponent
- * format[2] = # of bits in mantissa
- * format[3] = start bit of sign
- * format[4] = start bit of exponent
- * format[5] = start bit of mantissa
- * format[6] = high order mantissa bit (CRAY needs this)
- * format[7] = bias of exponent
- */
- assert(d->format && d->format[0] == 8*d->size);
- nbits = d->format[0];
- spos = nbits - (d->format[3]+1);
- esize = d->format[1];
- epos = nbits - (d->format[4]+esize);
- msize = d->format[2];
- mpos = nbits - (d->format[5]+msize);
- H5Tset_fields(type, spos, epos, esize, mpos, msize);
- H5Tset_ebias(type, d->format[7]);
- }
- return type;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_space
- *
- * Purpose: Convert a PDB dimension list into an HDF5 data space.
- *
- * Return: Success: HDF5 data space
- *
- * Failure: negative
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static hid_t
-fix_space(const dimdes *dim)
-{
- hsize_t size[H5S_MAX_RANK];
- int rank;
-
- for (rank=0; rank<H5S_MAX_RANK && dim; rank++, dim=dim->next) {
- size[rank] = dim->number;
- }
- if (rank>=H5S_MAX_RANK) return -1;
- return H5Screate_simple(rank, size, NULL);
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_external
- *
- * Purpose: Sets the external file information for a dataset creation
- * property list based on information from PDB.
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-fix_external(hid_t dcpl, const char *pdb_file_name, long nelmts,
- hsize_t elmt_size, symblock *block)
-{
- int i;
-
- for (i=0; nelmts>0; i++) {
- hsize_t nbytes = block[i].number * elmt_size;
- H5Pset_external(dcpl, pdb_file_name, block[i].diskaddr, nbytes);
- nelmts -= block[i].number;
- }
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: traverse
- *
- * Purpose: Traverse the current working directory of the PDB file.
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static int
-traverse(PDBfile *pdb, const char *pdb_file_name, hid_t hdf)
-{
- int nitems, i, in_subdir=FALSE;
- char **list=NULL;
- hid_t group=-1, h_type=-1, h_space=-1, dset=-1, dcpl=-1;
- hsize_t elmt_size;
- const syment *ep=NULL;
-
- if (NULL==(list=PD_ls(pdb, ".", NULL, &nitems))) {
- fprintf(stderr, "cannot obtain PDB directory contents\n");
- goto error;
- }
-
- for (i=0; i<nitems; i++) {
- ep = PD_inquire_entry(pdb, list[i], TRUE, NULL);
- if (verbose_g) {
- printf("%s %s\n", _PD_fixname(pdb, list[i]), ep->type);
- fflush(stdout);
- }
-
-
- if ('/'==list[i][strlen(list[i])-1]) {
- /*
- * This is a PDB directory. Make a corresponding HDF5 group and
- * traverse into that PDB directory and HDF5 group
- */
- if ((group=H5Gcreate(hdf, list[i], 0))<0) {
- fprintf(stderr, "cannot create HDF group %s\n", list[i]);
- goto error;
- }
- if (!PD_cd(pdb, list[i])) {
- fprintf(stderr, "cannot cd into PDB directory %s\n", list[i]);
- goto error;
- } else {
- in_subdir = TRUE;
- }
-
- traverse(pdb, pdb_file_name, group);
- if (!PD_cd(pdb, "..")) {
- fprintf(stderr, "cannot traverse out of PDB %s\n", list[i]);
- goto error;
- }
- H5Gclose(group);
-
- } else {
- /* This is some non-directory PDB object */
-
- /* Create an HDF5 datatype from the PDB type */
- if ((h_type=fix_type(pdb, ep->type))<0) {
- fprintf(stderr, "cannot create datatype for %s (%s)\n",
- list[i], ep->type);
- continue;
- }
- elmt_size = H5Tget_size(h_type);
-
- /* Create an HDF5 dataspace from the PDB dimensions */
- if ((h_space=fix_space(ep->dimensions))<0) {
- fprintf(stderr, "cannot create datatype for %s\n", list[i]);
- continue;
- }
-
- /* Create pointers to the external PDB data */
- dcpl = H5Pcreate(H5P_DATASET_CREATE);
- fix_external(dcpl, pdb_file_name, ep->number, elmt_size,
- ep->blocks);
-
- /* Create the dataset */
- if ((dset=H5Dcreate(hdf, list[i], h_type, h_space, dcpl))<0) {
- fprintf(stderr, "cannot create dataset for %s\n", list[i]);
- }
-
- H5Pclose(dcpl);
- H5Dclose(dset);
- H5Sclose(h_space);
- H5Tclose(h_type);
- }
-
- }
-
- for (i=0; i<nitems; i++) {
- SC_free(list[i]);
- }
- SC_free(list);
- return 0;
-
- error:
- if (group>=0) H5Gclose(group);
- if (in_subdir) PD_cd(pdb, "..");
- if (list) {
- for (i=0; i<nitems; i++) {
- SC_free(list[i]);
- }
- SC_free(list);
- }
- return -1;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: main
- *
- * Purpose: Create an HDF5 file from a PDB file.
- *
- * Return: Success: 0
- *
- * Failure: non-zero
- *
- * Programmer: Robb Matzke
- * Tuesday, October 12, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-main(int argc, char *argv[])
-{
- int argno;
- char _hdf_name[512], *hdf_name, *pdb_name, *s;
- PDBfile *pdb;
- hid_t hdf, fapl;
-
- /* Print a help message if called with no arguments */
- if (1==argc) {
- usage(argv[0]);
- exit(1);
- }
-
- /* Process arguments in order; switches interspersed with files */
- for (argno=1; argno<argc; argno++) {
- if (!strcmp("--help", argv[argno])) {
- usage(argv[0]);
- exit(1);
- } else if (!strcmp("--verbose", argv[argno])) {
- verbose_g++;
- } else if (!strcmp("--cached", argv[argno])) {
- cached_g++;
- } else if (!strcmp("--version", argv[argno])) {
- version(argv[0]);
- } else if ('-'==argv[argno][0] && '-'!=argv[argno][1]) {
- for (s=argv[argno]+1; *s; s++) {
- switch (*s) {
- case '?':
- case 'h': /*--help*/
- usage(argv[0]);
- exit(0);
- case 'c': /*--cached*/
- cached_g++;
- break;
- case 'v': /*--verbose*/
- verbose_g++;
- break;
- case 'V': /*--version*/
- version(argv[0]);
- break;
- default:
- usage(argv[0]);
- exit(1);
- }
- }
- } else if ('-'==argv[argno][0]) {
- usage(argv[0]);
- exit(1);
- } else {
- /* This must be a file name. Process it. */
- fapl = H5Pcreate(H5P_FILE_ACCESS);
- if (cached_g) H5Pset_fapl_core(fapl, 1024*1024, TRUE);
-
- pdb_name = argv[argno];
- hdf_name = fix_name(argv[argno], _hdf_name, sizeof _hdf_name);
- if (NULL==(pdb=PD_open(pdb_name, "r"))) {
- fprintf(stderr, "%s: unable to open PDB file\n", pdb_name);
- exit(1);
- }
- if ((hdf=H5Fcreate(hdf_name, H5F_ACC_TRUNC, H5P_DEFAULT,
- fapl))<0) {
- fprintf(stderr, "%s: unable to open HDF file\n", hdf_name);
- exit(1);
- }
- H5Pclose(fapl);
-
- /*
- * Traverse the PDB file to create the HDF5 file.
- */
- traverse(pdb, pdb_name, hdf);
-
- /* Close the files */
- if (!PD_close(pdb)) {
- fprintf(stderr, "%s: problems closing PDB file\n", pdb_name);
- exit(1);
- }
- if (H5Fclose(hdf)<0) {
- fprintf(stderr, "%s: problems closing HDF file\n", hdf_name);
- exit(1);
- }
- }
- }
- return 0;
-}
diff --git a/tools/testh4toh5.sh b/tools/testh4toh5.sh
deleted file mode 100755
index 658fb9d..0000000
--- a/tools/testh4toh5.sh
+++ /dev/null
@@ -1,246 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 1997 National Center for Supercomputing Applications.
-# All rights reserved.
-#
-# Test script for the h4toh5 tests.
-# Using the h4toh5 convert to convert a pre-created hdf file to
-# an hdf5 file (output file), then compare it with a pre-created
-# corresponding hdf5 file (expected file).
-# If the same, that particular test passes.
-# If not the same, the output file and expected file are processed
-# by the h5dump tool to see if they produce the same results.
-# If the same, the test passes.
-# If not, show the difference of the two results and report the test failed.
-#
-# h5dump is default to use the one just built. It can be overridden
-# by setting $H5DUMP to a different value such as /usr/local/bin/h5dump.
-
-h4toh5=h4toh5 # a relative name
-
-COMMAND=`pwd`/"$h4toh5" # an absolute command name
-
-cmp='cmp -s'
-diff='diff -c'
-
-RM='rm -f'
-SED='sed '
-H5DUMP=${H5DUMP:-`pwd`/'h5dump'} # Default to use the h5dumper
- # in the same tools directory
-
-# Verify if $H5DUMP is a valid command.
-tmpfile=/tmp/testh4toh5.$$
-$H5DUMP -V > $tmpfile
-if [ ! -s $tmpfile ]; then
- echo " Could not run the '$H5DUMP' command. The test can still proceed"
- echo " but it may fail if '$H5DUMP' is needed to verify the output."
- echo " You can make sure '$H5DUMP' is among your shell PATH and run"
- echo " the test again. You may also visit http://hdf.ncsa.uiuc.edu"
- echo " or email hdfhelp@ncsa.uiuc.edu for more information."
- H5DUMP=:
-fi
-$RM $tmpfile
-
-# The build (current) directory might be different than the source directory.
-if test "X$srcdir" = X; then
- srcdir=.
-fi
-mkdir testfiles >/dev/null 2>&1
-
-SRCDIR="$srcdir/testfiles"
-OUTDIR="./testfiles/Results"
-
-test -d "$OUTDIR" || mkdir $OUTDIR
-
-nerrors=0
-verbose=yes
-
-# Print a line-line message left justified in a field of 70 characters
-# beginning with the word "Testing".
-TESTING()
-{
- SPACES=" "
- echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\012'
-}
-
-# Run a test and print PASS or *FAIL*. If a test fails then increment
-# the `nerrors' global variable and (if $verbose is set) display the
-# difference between the actual and the expected hdf4 files. The
-# expected hdf5 files are in testfiles/Expected directory.
-# The actual hdf5 file is not removed if $HDF5_NOCLEANUP is to a non-null
-# value.
-CONVERT()
-{
- # Run h4toh5 convert.
- TESTING $h4toh5 $@
-
- #
- # Set up arguments to run the conversion test.
- # The converter assumes all hdf4 files has the .hdf suffix as in the form
- # of foo.hdf. It creates the corresponding hdf5 files with the .h5 suffix
- # as in the form of foo.h5. One exception is that if exactly two file
- # names are given, it treats the first argument as an hdf4 file and creates
- # the corresponding hdf5 file with the name as the second argument, WITOUT
- # any consideration of the suffix. (For this test script, in order to
- # match the output hdf5 file with the expected hdf5 file, it expects the
- # second file of the two-files tests has the .h5 suffix too.)
- #
- # If SRCDIR != OUTDIR, need to copy the input hdf4 files from the SRCDIR
- # to the OUTDIR and transform the input file pathname because of the suffix
- # convention mentioned above. This way, the hdf5 files are always created
- # in the OUTDIR directory.
- #
-
- INFILES=""
- OUTFILES=""
- MULTIRUN=""
-
- case "$1" in
- "-m") # multiple files conversion
- MULTIRUN="-m"
- shift
- for f in $*
- do
- if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$f $OUTDIR/$f
- fi
- INFILES="$INFILES $f"
- OUTFILES="$OUTFILES `basename $f .hdf`.h5"
- shift
- done
- ;;
- * ) # Single file conversion
- case $# in
- 1) if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$1 $OUTDIR/$1
- fi
- INFILES="$1"
- OUTFILES="`basename $1 .hdf`.h5"
- ;;
- 2) # hdf4 file specified
- if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$1 $OUTDIR/$1
- fi
- INFILES="$1"
- OUTFILES="$2"
- ;;
- *) # Illegal
- echo "Illegal arguments"
- exit 1
- ;;
- esac
- ;;
- esac
-
- # run the conversion and remove input files that have been copied over
- (
- cd $OUTDIR
- $COMMAND $INFILES $OUTFILES 2>/dev/null
- if test "$SRCDIR" != "$OUTDIR"; then
- $RM $INFILES
- fi
- )
-
- # Verify results
- result="passed"
- for f in $OUTFILES
- do
- if $cmp $SRCDIR/Expected/$f $OUTDIR/$f
- then
- :
- else
- # Use h5dump to dump the files and verify the output.
- outfile=`basename $f .h5`
- expect_out=$outfile.expect
- actual_out=$outfile.actual
-
- (cd $SRCDIR/Expected
- $H5DUMP $outfile.h5 ) > $expect_out
- (cd $OUTDIR
- $H5DUMP $outfile.h5 ) > $actual_out
-
- if [ "passed" = $result -a ! -s $actual_out ] ; then
- echo "*FAILED*"
- nerrors="`expr $nerrors + 1`"
- result=failed
- test yes = "$verbose" &&
- echo " H5DUMP failed to produce valid output"
- elif $cmp $expect_out $actual_out; then
- :
- else
- if test "passed" = $result; then
- echo "*FAILED*"
- nerrors="`expr $nerrors + 1`"
- result=failed
- fi
- test yes = "$verbose" &&
- echo " Actual result (*.actual) differs from expected result (*.expect)" &&
- $diff $expect_out $actual_out |sed 's/^/ /'
- fi
- fi
-
- # Clean up output file
- if test -z "$HDF5_NOCLEANUP"; then
- $RM $expect_out $actual_out
- $RM $OUTDIR/$f
- fi
- done
- if test "passed" = "$result"; then
- echo " PASSED"
- fi
-}
-
-##############################################################################
-##############################################################################
-### T H E T E S T S ###
-##############################################################################
-##############################################################################
-
-$RM $OUTDIR/*.hdf $OUTDIR/*.tmp
-
-#
-# The HDF5 filenames are created based upon the HDF4 filenames
-# without the extension.
-#
-
-# test for converting H5 groups to H4 Vgroups.
-#CONVERT vg.hdf
-
-
-#
-# The test for conversion are the same as above with the only difference
-# being that the HDF5 filenames are given explicitly.
-#
-
-$RM $OUTDIR/*.tmp
-CONVERT anno_test.hdf anno_test.h5
-CONVERT gr_typ_test.hdf gr_typ_test.h5
-CONVERT grnameclash_test.hdf grnameclash_test.h5
-CONVERT image_attr_test.hdf image_attr_test.h5
-#CONVERT image_maxsize.hdf image_maxsize.h5
-CONVERT ras_24_test.hdf ras_24_test.h5
-CONVERT ras_8_test.hdf ras_8_test.h5
-CONVERT sds_attr_test.hdf sds_attr_test.h5
-CONVERT sds_dim_test.hdf sds_dim_test.h5
-CONVERT sds_typ_test.hdf sds_typ_test.h5
-CONVERT sdsnameclash_test.hdf sdsnameclash_test.h5
-CONVERT vdata_test.hdf vdata_test.h5
-CONVERT vdnameclash_test.hdf vdnameclash_test.h5
-CONVERT vg_hl_test.hdf vg_hl_test.h5
-CONVERT vg_loop_test.hdf vg_loop_test.h5
-CONVERT vgnameclash_test.hdf vgnameclash_test.h5
-CONVERT vg_all_test.hdf vg_all_test.h5
-#
-# Again, the test for conversion are the same as the first set of test.
-# Here, multiple conversion are done on HDF4 files at one time.
-#
-
-$RM $OUTDIR/*.hdf $OUTDIR/*.tmp
-#CONVERT -m vg.hdf
-
-if test $nerrors -eq 0 ; then
- echo "All h4toh5 tests passed."
-fi
-
-$RM -r $OUTDIR
-exit $nerrors
diff --git a/tools/testh5dump.sh b/tools/testh5dump.sh
deleted file mode 100755
index af2d26d..0000000
--- a/tools/testh5dump.sh
+++ /dev/null
@@ -1,197 +0,0 @@
-#! /bin/sh
-#
-# Copyright (C) 1998 - 2001
-# National Center for Supercomputing Applications
-# All rights reserved.
-#
-# Tests for the h5dump tool
-
-DUMPER=h5dump # The tool name
-DUMPER_BIN=`pwd`/$DUMPER # The path of the tool binary
-CMP='cmp -s'
-DIFF='diff -c'
-
-nerrors=0
-verbose=yes
-
-# The build (current) directory might be different than the source directory.
-if test -z "$srcdir"; then
- srcdir=.
-fi
-
-test -d testfiles || mkdir testfiles
-
-# Print a line-line message left justified in a field of 70 characters
-# beginning with the word "Testing".
-#
-TESTING() {
- SPACES=" "
- echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
-}
-
-# Run a test and print PASS or *FAIL*. If a test fails then increment
-# the `nerrors' global variable and (if $verbose is set) display the
-# difference between the actual output and the expected output. The
-# expected output is given as the first argument to this function and
-# the actual output file is calculated by replacing the `.ddl' with
-# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a
-# non-zero value.
-#
-TOOLTEST() {
- expect=$srcdir/testfiles/$1
- actual="testfiles/`basename $1 .ddl`.out"
- shift
-
- # Run test.
- TESTING $DUMPER $@
-
- (
- echo "#############################"
- echo "Expected output for '$DUMPER $@'"
- echo "#############################"
- cd $srcdir/testfiles
- $RUNSERIAL $DUMPER_BIN "$@"
- ) >$actual 2>&1
-
- if $CMP $expect $actual; then
- echo " PASSED"
- else
- echo "*FAILED*"
- echo " Expected result (*.ddl) differs from actual result (*.out)"
- nerrors="`expr $nerrors + 1`"
- test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /'
- fi
-
- # Clean up output file
- if test -z "$HDF5_NOCLEANUP"; then
- rm -f $actual
- fi
-}
-
-##############################################################################
-##############################################################################
-### T H E T E S T S ###
-##############################################################################
-##############################################################################
-
-# test for displaying groups
-TOOLTEST tgroup-1.ddl tgroup.h5
-# test for displaying the selected groups
-TOOLTEST tgroup-2.ddl --group=/g2 --group / -g /y tgroup.h5
-
-# test for displaying simple space datasets
-TOOLTEST tdset-1.ddl tdset.h5
-# test for displaying selected datasets
-TOOLTEST tdset-2.ddl -H -d dset1 -d /dset2 --dataset=dset3 tdset.h5
-
-# test for displaying attributes
-TOOLTEST tattr-1.ddl tattr.h5
-# test for displaying the selected attributes of string type and scalar space
-TOOLTEST tattr-2.ddl -a /attr1 --attribute /attr4 --attribute=/attr5 tattr.h5
-# test for header and error messages
-TOOLTEST tattr-3.ddl --header -a /attr2 --attribute=/attr tattr.h5
-
-# test for displaying soft links
-TOOLTEST tslink-1.ddl tslink.h5
-# test for displaying the selected link
-TOOLTEST tslink-2.ddl -l slink2 tslink.h5
-
-# tests for hard links
-TOOLTEST thlink-1.ddl thlink.h5
-TOOLTEST thlink-2.ddl -d /g1/dset2 --dataset /dset1 --dataset=/g1/g1.1/dset3 thlink.h5
-TOOLTEST thlink-3.ddl -d /g1/g1.1/dset3 --dataset /g1/dset2 --dataset=/dset1 thlink.h5
-TOOLTEST thlink-4.ddl -g /g1 thlink.h5
-TOOLTEST thlink-5.ddl -d /dset1 -g /g2 -d /g1/dset2 thlink.h5
-
-# tests for compound data types
-TOOLTEST tcomp-1.ddl tcompound.h5
-# test for named data types
-TOOLTEST tcomp-2.ddl -t /type1 --datatype /type2 --datatype=/group1/type3 tcompound.h5
-# test for unamed type
-TOOLTEST tcomp-3.ddl -t /#5992:0 -g /group2 tcompound.h5
-
-#test for the nested compound type
-TOOLTEST tnestcomp-1.ddl tnestedcomp.h5
-
-# test for options
-TOOLTEST tall-1.ddl tall.h5
-TOOLTEST tall-2.ddl --header -g /g1/g1.1 -a attr2 tall.h5
-TOOLTEST tall-3.ddl -d /g2/dset2.1 -l /g1/g1.2/g1.2.1/slink tall.h5
-
-# test for loop detection
-TOOLTEST tloop-1.ddl tloop.h5
-
-# test for string
-TOOLTEST tstr-1.ddl tstr.h5
-TOOLTEST tstr-2.ddl tstr2.h5
-
-# test for file created by Lib SAF team
-TOOLTEST tsaf.ddl tsaf.h5
-
-# test for file with variable length data
-TOOLTEST tvldtypes1.ddl tvldtypes1.h5
-TOOLTEST tvldtypes2.ddl tvldtypes2.h5
-TOOLTEST tvldtypes3.ddl tvldtypes3.h5
-TOOLTEST tvldtypes4.ddl tvldtypes4.h5
-
-# test for files with array data
-TOOLTEST tarray1.ddl tarray1.h5
-TOOLTEST tarray2.ddl tarray2.h5
-TOOLTEST tarray3.ddl tarray3.h5
-TOOLTEST tarray4.ddl tarray4.h5
-TOOLTEST tarray5.ddl tarray5.h5
-TOOLTEST tarray6.ddl tarray6.h5
-TOOLTEST tarray7.ddl tarray7.h5
-
-# test for files with empty data
-TOOLTEST tempty.ddl tempty.h5
-
-# test XML
-TOOLTEST tall.h5.xml --xml tall.h5
-TOOLTEST tattr.h5.xml --xml tattr.h5
-TOOLTEST tbitfields.h5.xml --xml tbitfields.h5
-TOOLTEST tcompound.h5.xml --xml tcompound.h5
-TOOLTEST tcompound2.h5.xml --xml tcompound2.h5
-TOOLTEST tdatareg.h5.xml --xml tdatareg.h5
-TOOLTEST tdset.h5.xml --xml tdset.h5
-TOOLTEST tdset2.h5.xml --xml tdset2.h5
-TOOLTEST tenum.h5.xml --xml tenum.h5
-TOOLTEST tgroup.h5.xml --xml tgroup.h5
-TOOLTEST thlink.h5.xml --xml thlink.h5
-TOOLTEST tloop.h5.xml --xml tloop.h5
-TOOLTEST tloop2.h5.xml --xml tloop2.h5
-TOOLTEST tmany.h5.xml --xml tmany.h5
-TOOLTEST tnestedcomp.h5.xml --xml tnestedcomp.h5
-TOOLTEST tobjref.h5.xml --xml tobjref.h5
-TOOLTEST topaque.h5.xml --xml topaque.h5
-TOOLTEST tslink.h5.xml --xml tslink.h5
-TOOLTEST tstr.h5.xml --xml tstr.h5
-TOOLTEST tstr2.h5.xml --xml tstr2.h5
-TOOLTEST tref.h5.xml --xml tref.h5
-TOOLTEST tname-amp.h5.xml --xml tname-amp.h5
-TOOLTEST tname-apos.h5.xml --xml tname-apos.h5
-TOOLTEST tname-gt.h5.xml --xml tname-gt.h5
-TOOLTEST tname-lt.h5.xml --xml tname-lt.h5
-TOOLTEST tname-quot.h5.xml --xml tname-quot.h5
-TOOLTEST tname-sp.h5.xml --xml tname-sp.h5
-TOOLTEST tstring.h5.xml --xml tstring.h5
-TOOLTEST tstring-at.h5.xml --xml tstring-at.h5
-TOOLTEST tref-escapes.h5.xml --xml tref-escapes.h5
-TOOLTEST tref-escapes-at.h5.xml --xml tref-escapes-at.h5
-TOOLTEST tnodata.h5.xml --xml tnodata.h5
-TOOLTEST tarray1.h5.xml --xml tarray1.h5
-TOOLTEST tarray2.h5.xml --xml tarray2.h5
-TOOLTEST tarray3.h5.xml --xml tarray3.h5
-TOOLTEST tarray6.h5.xml --xml tarray6.h5
-TOOLTEST tarray7.h5.xml --xml tarray7.h5
-TOOLTEST tvldtypes1.h5.xml --xml tvldtypes1.h5
-TOOLTEST tvldtypes2.h5.xml --xml tvldtypes2.h5
-TOOLTEST tvldtypes3.h5.xml --xml tvldtypes3.h5
-TOOLTEST tsaf.h5.xml --xml tsaf.h5
-TOOLTEST tempty.h5.xml --xml tempty.h5
-
-if test $nerrors -eq 0 ; then
- echo "All $DUMPER tests passed."
-fi
-
-exit $nerrors
diff --git a/tools/testh5ls.sh b/tools/testh5ls.sh
deleted file mode 100755
index 9f659fc..0000000
--- a/tools/testh5ls.sh
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/bin/sh
-# Tests for the h5ls tool
-
-h5tool=h5ls # The tool name
-h5tool_bin=`pwd`/$h5tool # The path of the tool binary
-CMP='cmp -s'
-DIFF='diff -c'
-NLINES=20 # Max. lines of output to display if test fails
-
-nerrors=0
-verbose=yes
-
-# The build (current) directory might be different than the source directory.
-if test "X$srcdir" = X; then
- srcdir=.
-fi
-test -d testfiles || mkdir testfiles
-
-# Print a line-line message left justified in a field of 70 characters
-# beginning with the word "Testing".
-TESTING()
-{
- SPACES=" "
- echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\012'
-}
-
-# Run a test and print PASS or *FAIL*. For now, if h5ls can complete
-# with exit status 0, consider it pass. If a test fails then increment
-# the `nerrors' global variable and (if $verbose is set) display up to $NLINS
-# lines of the actual output from the tool test. The actual output is not
-# removed if $HDF5_NOCLEANUP has a non-zero value.
-# Arguemnts:
-# $1 -- actual output filename to use
-# $2 and on -- argument for the h5ls tool
-TOOLTEST()
-{
- actual="testfiles/`basename $1 .ls`.out"
- expect=$srcdir/testfiles/$1
- shift
-
- # Run test.
- # Stderr is included in stdout so that the diff can detect
- # any unexpected output from that stream too.
- TESTING $h5tool $@
- (
- echo "#############################"
- echo " output for '$h5tool $@'"
- echo "#############################"
- cd $srcdir/testfiles
- $RUNSERIAL $h5tool_bin "$@"
- ) >$actual 2>& 1
-
- exitcode=$?
- if [ $exitcode -ne 0 ]; then
- echo "*FAILED*"
- nerrors="`expr $nerrors + 1`"
- if [ yes = "$verbose" ]; then
- echo "test returned with exit code $exitcode"
- echo "test output: (up to $NLINES lines)"
- head -$NLINES $actual
- echo "***end of test output***"
- echo ""
- fi
- elif [ ! -f $expect ]; then
- # Create the expect file if it doesn't yet exist.
- echo " CREATED"
- cp $actual $expect
- elif $CMP $expect $actual; then
- echo " PASSED"
- else
- echo "*FAILED*"
- echo " Expected result differs from actual result"
- nerrors="`expr $nerrors + 1`"
- test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /'
- fi
-
- # Clean up output file
- if [ X = ${HDF5_NOCLEANUP:-X} ]; then
- rm -f $actual
- fi
-}
-
-
-
-##############################################################################
-##############################################################################
-### T H E T E S T S ###
-##############################################################################
-##############################################################################
-
-# Toss in a bunch of tests. Not sure if they are the right kinds.
-# test the help syntax
-TOOLTEST help-1.ls -w80 -h
-TOOLTEST help-2.ls -w80 -help
-TOOLTEST help-3.ls -w80 -?
-
-# test simple command
-TOOLTEST tall-1.ls -w80 tall.h5
-TOOLTEST tall-2.ls -w80 -r -d tall.h5
-TOOLTEST tgroup.ls -w80 tgroup.h5
-
-# test for displaying groups
-TOOLTEST tgroup-1.ls -w80 -r -g tgroup.h5
-
-# test for displaying simple space datasets
-TOOLTEST tdset-1.ls -w80 -r -d tdset.h5
-
-# test for displaying soft links
-TOOLTEST tslink-1.ls -w80 -r tslink.h5
-
-# tests for hard links
-TOOLTEST thlink-1.ls -w80 thlink.h5
-
-# tests for compound data types
-TOOLTEST tcomp-1.ls -w80 -r -d tcompound.h5
-
-#test for the nested compound type
-TOOLTEST tnestcomp-1.ls -w80 -r -d tnestedcomp.h5
-
-# test for loop detection
-TOOLTEST tloop-1.ls -w80 -r -d tloop.h5
-
-# test for string
-TOOLTEST tstr-1.ls -w80 -r -d tstr.h5
-
-# test test file created from lib SAF team
-TOOLTEST tsaf.ls -w80 -r -d tsaf.h5
-
-# test for variable length data types
-TOOLTEST tvldtypes1.ls -w80 -r -d tvldtypes1.h5
-
-# test for array data types
-TOOLTEST tarray1.ls -w80 -r -d tarray1.h5
-
-# test for empty data
-TOOLTEST tempty.ls -w80 -d tempty.h5
-
-if test $nerrors -eq 0 ; then
- echo "All $h5tool tests passed."
-fi
-
-exit $nerrors
diff --git a/tools/testh5toh4.sh b/tools/testh5toh4.sh
deleted file mode 100755
index 7e4e0f2..0000000
--- a/tools/testh5toh4.sh
+++ /dev/null
@@ -1,301 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 1997 National Center for Supercomputing Applications.
-# All rights reserved.
-#
-
-h5toh4=h5toh4 # a relative name
-COMMAND=`pwd`/"$h5toh4" # an absolute command path
-
-cmp='cmp -s'
-diff='diff -c'
-
-RM='rm -f'
-SED='sed '
-H4DUMP='hdp'
-
-# Verify if $H4DUMP is a valid command.
-tmpfile=/tmp/testh5toh4.$$
-$H4DUMP -H > $tmpfile
-if test -s "$tmpfile"; then
- # Find out which version of hdp is being used. Over simplified
- # algorithm but will do the job for now.
- if ( grep -s 'NCSA HDF Version 4.1 Release [3-9]' $tmpfile > /dev/null )
- then
- H4DUMPVER=413
- else
- H4DUMPVER=0
- echo " Some tests maybe skipped because your version of $H4DUMP does"
- echo " not handle loops in Vgroups correctly. You need version"
- echo " 4.1 Release 3 or later. Visit http://hdf.ncsa.uiuc.edu"
- echo " or email hdfhelp@ncsa.uiuc.edu for more information."
- fi
-else
- echo " Could not run the '$H4DUMP' command. The test can still proceed"
- echo " but it may fail if '$H4DUMP' is needed to verify the output."
- echo " You can make sure '$H4DUMP' is among your shell PATH and run"
- echo " the test again. You may also visit http://hdf.ncsa.uiuc.edu"
- echo " or email hdfhelp@ncsa.uiuc.edu for more information."
- H4DUMP=:
- H4DUMPVER=0
-fi
-$RM $tmpfile
-
-# The build (current) directory might be different than the source directory.
-if test -z "$srcdir"; then
- srcdir=.
-fi
-mkdir testfiles >/dev/null 2>&1
-
-SRCDIR="$srcdir/testfiles"
-OUTDIR="./testfiles/Results"
-
-test -d $OUTDIR || mkdir $OUTDIR
-
-nerrors=0
-verbose=yes
-
-# Print a line-line message left justified in a field of 70 characters
-# beginning with the word "Testing".
-TESTING()
-{
- SPACES=" "
- echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\012'
-}
-
-# Run a test and print PASS or *FAIL*. If a test fails then increment
-# the `nerrors' global variable and (if $verbose is set) display the
-# difference between the actual and the expected hdf4 files. The
-# expected hdf4 files are in testfiles/Expected directory.
-# The actual hdf4 file is not removed if $HDF5_NOCLEANUP is to a non-null
-# value.
-CONVERT()
-{
- # Run h5toh4 convert.
- TESTING $h5toh4 $@
-
- #
- # Set up arguments to run the conversion test.
- # The converter assumes all hdf5 files has the .h5 suffix as in the form
- # of foo.h5. It creates the corresponding hdf4 files with the .hdf suffix
- # as in the form of foo.hdf. One exception is that if exactly two file
- # names are given, it treats the first argument as an hdf5 file and creates
- # the corresponding hdf4 file with the name as the second argument, WITOUT
- # any consideration of the suffix. (For this test script, in order to
- # match the output hdf4 file with the expected hdf4 file, it expects the
- # second file of the two-files tests has the .hdf suffix too.)
- #
- # If SRCDIR != OUTDIR, need to copy the input hdf5 files from the SRCDIR
- # to the OUTDIR and transform the input file pathname because of the suffix
- # convention mentioned above. This way, the hdf4 files are always created
- # in the OUTDIR directory.
- #
-
- INFILES=""
- OUTFILES=""
- MULTIRUN=""
-
- case "$1" in
- "-m") # multiple files conversion
- MULTIRUN="-m"
- shift
- for f in $*
- do
- if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$f $OUTDIR/$f
- fi
- INFILES="$INFILES $f"
- OUTFILES="$OUTFILES `basename $f .h5`.hdf"
- shift
- done
- ;;
- * ) # Single file conversion
- case $# in
- 1) if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$1 $OUTDIR/$1
- fi
- INFILES="$1"
- OUTFILES="`basename $1 .h5`.hdf"
- ;;
- 2) # hdf4 file specified
- if test "$SRCDIR" != "$OUTDIR"; then
- cp $SRCDIR/$1 $OUTDIR/$1
- fi
- INFILES="$1"
- OUTFILES="$2"
- ;;
- *) # Illegal
- echo "Illegal arguments"
- exit 1
- ;;
- esac
- ;;
- esac
-
- # run the conversion and remove input files that have been copied over
- (
- cd $OUTDIR
- $COMMAND $MULTIRUN $INFILES 2>/dev/null
- if test "$SRCDIR" != "$OUTDIR"; then
- $RM $INFILES
- fi
- )
-
- # Verify results
- result="passed"
- for f in $OUTFILES
- do
- if $cmp $SRCDIR/Expected/$f $OUTDIR/$f
- then
- :
- else
- # Use hdp to dump the files and verify the output.
- # Filter out the output of "reference = ..." because
- # reference numbers are immaterial in general.
- outfile=`basename $f .hdf`
- expect_out=$outfile.expect
- actual_out=$outfile.actual
-
- if [ $outfile = "tloop" -a $H4DUMPVER -lt 413 ]
- then
- echo " -SKIP-"
- result="skipped"
- touch $expect_out $actual_out # fake them
- else
- (cd $SRCDIR/Expected
- $H4DUMP dumpvg $outfile.hdf
- $H4DUMP dumpvd $outfile.hdf
- $H4DUMP dumpsds $outfile.hdf ) |
- sed -e 's/reference = [0-9]*;//' > $expect_out
- (cd $OUTDIR
- $H4DUMP dumpvg $outfile.hdf
- $H4DUMP dumpvd $outfile.hdf
- $H4DUMP dumpsds $outfile.hdf ) |
- sed -e 's/reference = [0-9]*;//' > $actual_out
- fi
-
- if [ "passed" = $result -a ! -s $actual_out ] ; then
- echo "*FAILED*"
- nerrors="`expr $nerrors + 1`"
- result=failed
- test yes = "$verbose" &&
- echo " H4DUMP failed to produce valid output"
- elif $cmp $expect_out $actual_out; then
- :
- else
- if test "passed" = $result; then
- echo "*FAILED*"
- nerrors="`expr $nerrors + 1`"
- result=failed
- fi
- test yes = "$verbose" &&
- echo " Actual result (*.actual) differs from expected result (*.expect)" &&
- $diff $expect_out $actual_out |sed 's/^/ /'
- fi
- fi
-
- # Clean up output file
- if test -z "$HDF5_NOCLEANUP"; then
- $RM $expect_out $actual_out
- $RM $OUTDIR/$f
- fi
- done
- if test "passed" = "$result"; then
- echo " PASSED"
- fi
-}
-
-
-
-##############################################################################
-##############################################################################
-### T H E T E S T S ###
-##############################################################################
-##############################################################################
-
-$RM $OUTDIR/*.hdf $OUTDIR/*.tmp
-
-#
-# The HDF4 filenames are created based upon the HDF5 filenames
-# without the extension.
-#
-
-# test for converting H5 groups to H4 Vgroups.
-CONVERT tgroup.h5
-
-# test for converting H5 datasets to H4 SDS's.
-CONVERT tdset.h5
-
-# test for converting H5 attributes to H4 attributes.
-CONVERT tattr.h5
-
-# test for converting H5 soft links.
-CONVERT tslink.h5
-
-# test for converting H5 hard links.
-CONVERT thlink.h5
-
-# test for converting H5 compound data type to H4 Vdata.
-CONVERT tcompound.h5
-
-# test for converting all H5 objects at in same file.
-CONVERT tall.h5
-
-# tests for converting H5 objects with loops.
-CONVERT tloop.h5
-
-# test for converting extendable H5 datasets to H4 SDS's.
-CONVERT tdset2.h5
-
-# test for converting extendable H5 datasets with compound data type to H4 Vdata.
-CONVERT tcompound2.h5
-
-# tests for converting H5 objects from many different pathways.
-CONVERT tmany.h5
-
-# tests for converting H5 string objects.
-CONVERT tstr.h5
-
-# tests for converting more H5 string objects.
-CONVERT tstr2.h5
-
-#
-# The test for conversion are the same as above with the only difference
-# being that the HDF4 filenames are given explicitly.
-#
-
-$RM $OUTDIR/*.tmp
-CONVERT tgroup.h5 tgroup.hdf
-CONVERT tdset.h5 tdset.hdf
-CONVERT tattr.h5 tattr.hdf
-CONVERT tslink.h5 tslink.hdf
-CONVERT thlink.h5 thlink.hdf
-CONVERT tcompound.h5 tcompound.hdf
-CONVERT tall.h5 tall.hdf
-CONVERT tloop.h5 tloop.hdf
-CONVERT tdset2.h5 tdset2.hdf
-CONVERT tcompound2.h5 tcompound2.hdf
-CONVERT tmany.h5 tmany.hdf
-CONVERT tstr.h5 tstr.hdf
-CONVERT tstr2.h5 tstr2.hdf
-
-#
-# Again, the test for conversion are the same as the first set of test.
-# Here, multiple conversion are done on HDF5 files at one time.
-#
-
-$RM $OUTDIR/*.hdf $OUTDIR/*.tmp
-CONVERT -m tgroup.h5 tdset.h5 tattr.h5 tslink.h5 thlink.h5
-CONVERT -m tcompound.h5 tall.h5
-CONVERT -m tloop.h5
-CONVERT -m tdset2.h5 tcompound2.h5 tmany.h5
-CONVERT -m tstr.h5 tstr2.h5
-
-if test $nerrors -eq 0 ; then
- echo "All h5toh4 tests passed."
-fi
-
-if test -z "$HDF5_NOCLEANUP"; then
- $RM -r $OUTDIR
-fi
-exit $nerrors