summaryrefslogtreecommitdiffstats
path: root/src/H5Zfletcher32.c
blob: 1bf14f3295e7c22b13c593326ebeb1b89bf78683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  Raymond Lu<slu@ncsa.uiuc.edu>
 *              Jan 3, 2003
 */

#define H5Z_PACKAGE		/*suppress error about including H5Zpkg	  */

/* Pablo information */
/* (Put before include files to avoid problems with inline functions) */
#define PABLO_MASK	H5Z_fletcher32_mask

#include "H5private.h"		/* Generic Functions			*/
#include "H5Eprivate.h"		/* Error handling		  	*/
#include "H5Fprivate.h"         /* File access                          */
#include "H5MMprivate.h"	/* Memory management			*/
#include "H5Zpkg.h"		/* Data filters				*/

#ifdef H5_HAVE_FILTER_FLETCHER32

/* Interface initialization */
#define INTERFACE_INIT	NULL
static int interface_initialize_g = 0;

/* Local function prototypes */
static size_t H5Z_filter_fletcher32 (unsigned flags, size_t cd_nelmts,
    const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf);

/* This message derives from H5Z */
const H5Z_class_t H5Z_FLETCHER32[1] = {{
    H5Z_FILTER_FLETCHER32,	/* Filter id number		*/
    "fletcher32",		/* Filter name for debugging	*/
    NULL,                       /* The "can apply" callback     */
    NULL,                       /* The "set local" callback     */
    H5Z_filter_fletcher32,	/* The actual filter function	*/
}};

#define FLETCHER_LEN       4


/*-------------------------------------------------------------------------
 * Function:	H5Z_filter_fletcher32_compute
 *
 * Purpose:	Implement an Fletcher32 Checksum using 1's complement.
 *
 * Return:	Success: Fletcher32 value	
 *
 *		Failure: Can't fail
 *
 * Programmer:	Raymond Lu
 *              Jan 3, 2003
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static uint32_t
H5Z_filter_fletcher32_compute(void *_src, size_t len)
{
#if H5_SIZEOF_UINT16_T==2
    uint16_t *src=(uint16_t *)_src;
#else /* H5_SIZEOF_UINT16_T */
    /*To handle unusual platforms like Cray*/
    unsigned char *src=(unsigned char *)_src;
    unsigned short tmp_src;
#endif /* H5_SIZEOF_UINT16_T */
    size_t count = len;         /* Number of bytes left to checksum */
    uint32_t s1 = 0, s2 = 0;    /* Temporary partial checksums */

    FUNC_ENTER_NOINIT(H5Z_filter_fletcher32_compute)

    /* Compute checksum */
    while(count > 1) {
#if H5_SIZEOF_UINT16_T==2
        /*For normal platforms*/
        s1 += *src++;
#else /* H5_SIZEOF_UINT16_T */
        /*To handle unusual platforms like Cray*/
        tmp_src = (((unsigned short)src[0])<<8) | ((unsigned short)src[1]);
        src +=2;
        s1 += tmp_src;
#endif /* H5_SIZEOF_UINT16_T */
        if(s1 & 0xFFFF0000) { /*Wrap around carry if occurred*/
            s1 &= 0xFFFF;
            s1++;
        }
        s2 += s1;
        if(s2 & 0xFFFF0000) { /*Wrap around carry if occurred*/
            s2 &= 0xFFFF;
            s2++;
        }
        count -= 2;
    }

    if(count==1) {
        s1 += *(unsigned char*)src;
        if(s1 & 0xFFFF0000) { /*Wrap around carry if occurred*/
            s1 &= 0xFFFF;
            s1++;
        }
        s2 += s1;
        if(s2 & 0xFFFF0000) { /*Wrap around carry if occurred*/
            s2 &= 0xFFFF;
            s2++;
        }
    }

    FUNC_LEAVE_NOAPI((s2 << 16) + s1)
}


/*-------------------------------------------------------------------------
 * Function:	H5Z_filter_fletcher32
 *
 * Purpose:	Implement an I/O filter of Fletcher32 Checksum
 *
 * Return:	Success: Size of buffer filtered
 *		Failure: 0	
 *
 * Programmer:	Raymond Lu
 *              Jan 3, 2003
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
/* ARGSUSED */
static size_t
H5Z_filter_fletcher32 (unsigned flags, size_t UNUSED cd_nelmts, const unsigned UNUSED cd_values[], 
                     size_t nbytes, size_t *buf_size, void **buf)
{
    void    *outbuf = NULL;     /* Pointer to new buffer */
    unsigned char *src = (unsigned char*)(*buf);
    uint32_t fletcher;          /* Checksum value */
    size_t   ret_value;         /* Return value */
    
    FUNC_ENTER_NOAPI(H5Z_filter_fletcher32, 0)

    assert(sizeof(uint32_t)>=4);
   
    if (flags & H5Z_FLAG_REVERSE) { /* Read */
        /* Do checksum if it's enabled for read; otherwise skip it
         * to save performance. */
        if (!(flags & H5Z_FLAG_SKIP_EDC)) {
            unsigned char *tmp_src;             /* Pointer to checksum in buffer */
            size_t  src_nbytes = nbytes;        /* Original number of bytes */
            uint32_t stored_fletcher;           /* Stored checksum value */

            /* Get the stored checksum */
            src_nbytes -= FLETCHER_LEN;
            tmp_src=src+src_nbytes;
            UINT32DECODE(tmp_src, stored_fletcher);

            /* Compute checksum (can't fail) */
            fletcher = H5Z_filter_fletcher32_compute(src,src_nbytes);

            /* Verify computed checksum matches stored checksum */
            if(stored_fletcher != fletcher)
	        HGOTO_ERROR(H5E_STORAGE, H5E_READERROR, 0, "data error detected by Fletcher32 checksum")
        }
        
        /* Set return values */
        /* (Re-use the input buffer, just note that the size is smaller by the size of the checksum) */
        ret_value = nbytes-FLETCHER_LEN;
    } else { /* Write */
        unsigned char *dst;     /* Temporary pointer to destination buffer */

        /* Compute checksum (can't fail) */
        fletcher = H5Z_filter_fletcher32_compute(src,nbytes);
        
	if (NULL==(dst=outbuf=H5MM_malloc(nbytes+FLETCHER_LEN)))
	    HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate Fletcher32 checksum destination buffer")
        
        /* Copy raw data */
        HDmemcpy((void*)dst, (void*)(*buf), nbytes);

        /* Append checksum to raw data for storage */
        dst += nbytes;
        UINT32ENCODE(dst, fletcher);

        /* Free input buffer */
 	H5MM_xfree(*buf);

        /* Set return values */
        *buf_size = nbytes + FLETCHER_LEN;
	*buf = outbuf;
	outbuf = NULL;
	ret_value = *buf_size;           
    }

done:
    if(outbuf)
        H5MM_xfree(outbuf);
    FUNC_LEAVE_NOAPI(ret_value)
}
#endif /* H5_HAVE_FILTER_FLETCHER32 */

='#n809'>809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
/****h* H5Gf/H5Gf
 * PURPOSE
 *  This file contains C stubs for H5G Fortran APIs
 *
 * COPYRIGHT
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 ******
*/

#include "H5f90.h"
#include "H5Eprivate.h"

/****if* H5Gf/h5gcreate_c
 * NAME
 *  h5gcreate_c
 * PURPOSE
 *  Call H5Gcreate to create a group
 * INPUTS
 *  loc_id - file or group identifier
 *  name - name of the group
 *  namelen - name length
 *  size_hint - length of names in the group
 * OUTPUTS
 *  grp_id - group identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, August 5, 1999
 * HISTORY
 *
 *  Changed to call H5Gcreate2 because H5Gcreate flip-flops and
 *              H5Gcreate1 can be compiled out of the library
 *              QAK - 2007/08/23
 * SOURCE
*/
int_f
h5gcreate_c(hid_t_f *loc_id, _fcd name, int_f *namelen, size_t_f *size_hint,
	     hid_t_f *grp_id, hid_t_f *lcpl_id, hid_t_f *gcpl_id, hid_t_f *gapl_id )
/******/
{
    hid_t c_gcpl_id = -1;          /* Group creation property list */
    char *c_name = NULL;
    hid_t c_grp_id;
    int_f ret_value = -1;

    /*
     * Convert FORTRAN name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /*
     * Call H5Gcreate function.
     */
    if(*size_hint == (size_t_f)OBJECT_NAMELEN_DEFAULT_F ){
      c_grp_id = H5Gcreate2((hid_t)*loc_id, c_name,(hid_t)*lcpl_id,(hid_t)*gcpl_id,(hid_t)*gapl_id);}
    else {
      /* Create the group creation property list */
      if((c_gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
	goto DONE;

      /* Set the local heap size hint */
      if(H5Pset_local_heap_size_hint(c_gcpl_id, (size_t)*size_hint) < 0)
	goto DONE;

      /* Create the group */
      c_grp_id = H5Gcreate2((hid_t)*loc_id, c_name, H5P_DEFAULT, c_gcpl_id, H5P_DEFAULT);
    }
    if(c_grp_id < 0)
        goto DONE;

    /* Everything OK, set values to return */
    *grp_id = (hid_t_f)c_grp_id;
    ret_value = 0;

DONE:
    if(c_gcpl_id > 0)
        H5Pclose(c_gcpl_id);
    if(c_name)
        HDfree(c_name);
    return ret_value;
}

/****if* H5Gf/h5gopen_c
 * NAME
 *  h5gopen_c
 * PURPOSE
 *  Call H5Gopen to open a dataset
 * INPUTS
 *  loc_id - file or group identifier
 *  name - name of the group
 *  namelen - name length
 *  gapl_id - Group access property list identifier
 * OUTPUTS
 *  grp_id - group identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, August 5, 1999
 *
 * SOURCE
*/
int_f
h5gopen_c(hid_t_f *loc_id, _fcd name, int_f *namelen, hid_t_f *gapl_id, hid_t_f *grp_id)
/******/
{
     char *c_name = NULL;
     hid_t c_grp_id;
     int ret_value = -1;

     /*
      * Convert FORTRAN name to C name
      */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

     /*
      * Call H5Gopen function.
      */
    if((c_grp_id = H5Gopen2((hid_t)*loc_id, c_name, (hid_t)*gapl_id)) < 0)
        goto DONE;

    /* Everything OK, set values to return */
    *grp_id = (hid_t_f)c_grp_id;
    ret_value = 0;

DONE:
     if(c_name)
         HDfree(c_name);
     return ret_value;
}

/****if* H5Gf/h5gget_obj_info_idx_c
 * NAME
 *  h5gget_obj_info_idx_c
 * PURPOSE
 *  Call H5Gget_obj_info to return name and the type of group
 *  member
 * INPUTS
 *  loc_id - file or group identifier
 *  name - name of the group
 *  namelen - name length
 *  idx - index of the group member
 * OUTPUTS
 *  obj_name - buffer to store member's name
 *  obj_namelen - length of the buffer
 *  obj_type - type of the object
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, August 5, 1999
 * SOURCE
*/
int_f
h5gget_obj_info_idx_c(hid_t_f *loc_id, _fcd name, int_f *namelen, int_f *idx,
    _fcd obj_name, int_f *obj_namelen, int_f *obj_type)
/******/
{
    H5O_info_t oinfo;
    hid_t c_loc_id = (hid_t)*loc_id;
    char *c_name = NULL;
    size_t c_obj_namelen;
    char *c_obj_name = NULL;
    hsize_t c_idx = (hsize_t)*idx;
    hid_t gid = (-1);                 /* Temporary group ID */
    int ret_value = -1;

    /*
     * Convert FORTRAN name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /*
     * Allocate buffer to hold name of the object
     */
    c_obj_namelen = (size_t)*obj_namelen;
    if(c_obj_namelen)
       if(NULL == (c_obj_name = (char *)HDmalloc(c_obj_namelen + 1)))
           goto DONE;

    /* Get a temporary group ID for the group to query */
    if((gid = H5Gopen2(c_loc_id, c_name, H5P_DEFAULT)) < 0)
        goto DONE;

    /* Query the object's information */
    if(H5Lget_name_by_idx(gid, ".", H5_INDEX_NAME, H5_ITER_INC, c_idx, c_obj_name, c_obj_namelen, H5P_DEFAULT) < 0)
        goto DONE;
    if(H5Oget_info_by_idx(gid, ".", H5_INDEX_NAME, H5_ITER_INC, c_idx, &oinfo, H5P_DEFAULT) < 0)
        goto DONE;

/* XXX: Switch from using H5Gget_objtype_by_idx() means that this routine won't
 *  work on non-hard links - QAK
 */
    *obj_type = oinfo.type;

    /*
     * Convert C name to FORTRAN and place it in the given buffer
     */
    HD5packFstring(c_obj_name, _fcdtocp(obj_name), c_obj_namelen);
    ret_value = 0;

DONE:
    /* Close the temporary group, if it was opened */
    if(gid > 0)
        H5Gclose(gid);

    if(c_obj_name)
        HDfree(c_obj_name);
    if(c_name)
        HDfree(c_name);
    return ret_value;
}

/****if* H5Gf/h5gn_members_c
 * NAME
 *  h5gn_members_c
 * PURPOSE
 *  Call H5Gget_info_by_name to find number of objects in the group
 * INPUTS
 *  loc_id - file or group identifier
 *  name - name of the group
 *  namelen - name length
 * OUTPUTS
 *  nmemebers - number of members
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, August 5, 1999
 * SOURCE
*/
int_f
h5gn_members_c(hid_t_f *loc_id, _fcd name, int_f *namelen, int_f *nmembers)
/******/
{
    char *c_name = NULL;
    H5G_info_t ginfo;
    int ret_value = -1;

    /*
     * Convert FORTRAN name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /* Call H5Gget_info_by_name() for the number of objects in the group */
    if(H5Gget_info_by_name((hid_t)*loc_id, c_name, &ginfo, H5P_DEFAULT) < 0)
        goto DONE;

    *nmembers = (int_f)ginfo.nlinks;
    ret_value = 0;

DONE:
    if(c_name)
        HDfree(c_name);
    return ret_value;
}

/****if* H5Gf/h5gclose_c
 * NAME
 *  h5gclose_c
 * PURPOSE
 *  Call H5Gclose to close the group
 * INPUTS
 *  grp_id - identifier of the group to be closed
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, August 5, 1999
 * SOURCE
*/

int_f
h5gclose_c(hid_t_f *grp_id)
/******/
{
    int ret_value = 0;

    if(H5Gclose((hid_t)*grp_id) < 0)
        ret_value = -1;
    return ret_value;
}


/****if* H5Gf/h5glink_c
 * NAME
 *  h5glink_c
 * PURPOSE
 *  Call H5Glink to link the specified type
 * INPUTS
 *  loc_id - identifier of file or group
 *  link_type - link type
 *  current_name - name of the existing object for hard link,
 *  anything for the soft link
 *  current_namelen - current name lenghth
 *  new_name - new name for the object
 *  new_namelen - new_name lenghth
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * SOURCE
*/

int_f
h5glink_c(hid_t_f *loc_id, int_f *link_type, _fcd current_name,
    int_f *current_namelen, _fcd new_name, int_f *new_namelen)
/******/
{
    char *c_current_name = NULL, *c_new_name = NULL;
    int ret_value = -1;

    /*
    *  Convert Fortran name to C name
    */
    if(NULL == (c_current_name = (char *)HD5f2cstring(current_name, (size_t)*current_namelen)))
        goto DONE;
    if(NULL == (c_new_name = (char *)HD5f2cstring(new_name, (size_t)*new_namelen)))
        goto DONE;

    /*
    *  Call appropriate link creation function
    */
    switch((H5L_type_t)*link_type) {
        case H5L_TYPE_HARD:
            if(H5Lcreate_hard((hid_t)*loc_id, c_current_name, H5L_SAME_LOC, c_new_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
                goto DONE;
            break;

        case H5L_TYPE_SOFT:
            if(H5Lcreate_soft(c_current_name, (hid_t)*loc_id, c_new_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
                goto DONE;
            break;

    /* Cases below were added to remove the warnings in gcc 4.9.2 and probably other */
        case H5L_TYPE_EXTERNAL:
            ret_value = -1;
                goto DONE;
            break;

        case H5L_TYPE_MAX:
            ret_value = -1;
                goto DONE;
            break;

        case H5L_TYPE_ERROR:
            ret_value = -1;
                goto DONE;
            break;
    /* End of the warnings fix */
 
        default:        /* Unknown/unhandled link type */
            goto DONE;
    } /* end switch */
    ret_value = 0;

DONE:
    if(c_current_name)
        HDfree(c_current_name);
    if(c_new_name)
        HDfree(c_new_name);

    return ret_value ;
}

/****if* H5Gf/h5glink2_c
 * NAME
 *  h5glink2_c
 * PURPOSE
 *  Call H5Glink2 to link the specified type
 * INPUTS
 *  cur_loc_id - identifier of file or group
 *  cur_name - name of the existing object for hard link releative
 *  to cur_loc_id location,
 *  anything for the soft link
 *  current_namelen - current name lenghth
 *  link_type - link type
 *  new_loc_id - location identifier
 *  new_name - new name for the object releative to the new_loc_id
 *  location
 *  new_namelen - new_name lenghth
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, September 25, 2002
 * HISTORY
 *
 * SOURCE
*/

int_f
h5glink2_c(hid_t_f *cur_loc_id, _fcd cur_name, int_f *cur_namelen,
    int_f *link_type, hid_t_f *new_loc_id, _fcd new_name, int_f *new_namelen)
/******/
{
    char *c_cur_name = NULL, *c_new_name = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_cur_name = (char *)HD5f2cstring(cur_name, (size_t)*cur_namelen)))
        goto DONE;
    if(NULL == (c_new_name = (char *)HD5f2cstring(new_name, (size_t)*new_namelen)))
        goto DONE;

    /*
    *  Call appropriate link creation function
    */
    switch((H5L_type_t)*link_type) {
        case H5L_TYPE_HARD:
            if(H5Lcreate_hard((hid_t)*cur_loc_id, c_cur_name, (hid_t)*new_loc_id, c_new_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
                goto DONE;
            break;

        case H5L_TYPE_SOFT:
            if(H5Lcreate_soft(c_cur_name, (hid_t)*new_loc_id, c_new_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
                goto DONE;
            break;
    /* Cases below were added to remove the warnings in gcc 4.9.2 and probably other */
        case H5L_TYPE_EXTERNAL:
            ret_value = -1;
                goto DONE;
            break;

        case H5L_TYPE_MAX:
            ret_value = -1;
                goto DONE;
            break;

        case H5L_TYPE_ERROR:
            ret_value = -1;
                goto DONE;
            break;
    /* End of the warnings fix */

        default:        /* Unknown/unhandled link type */
            goto DONE;
    } /* end switch */
    ret_value = 0;

DONE:
    if(c_cur_name)
        HDfree(c_cur_name);
    if(c_new_name)
        HDfree(c_new_name);
    return ret_value ;
}

/****if* H5Gf/h5gunlink_c
 * NAME
 *  h5gunlink_c
 * PURPOSE
 *  Call H5Gunlink to remove  the specified name
 * INPUTS
 *  loc_id - identifier of file or group
 *  name - name of the object to unlink
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * SOURCE
*/

int_f
h5gunlink_c(hid_t_f *loc_id, _fcd name, int_f *namelen)
/******/
{
    char *c_name = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /*
     *  Call H5Gunlink function
     */
    if(H5Ldelete((hid_t)*loc_id, c_name, H5P_DEFAULT) < 0)
        goto DONE;
    ret_value = 0;

DONE:
    if(c_name)
        HDfree(c_name);
    return ret_value;
}

/****if* H5Gf/h5gmove_c
 * NAME
 *  h5gmove_c
 * PURPOSE
 *  Call H5Gmove to rename an object within an HDF5 file
 * INPUTS
 *  loc_id - identifier of file or group
 *  src_name - name of the original object
 *  src_namelen - original name lenghth
 *  dst_name - new name for the object
 *  dst_namelen - new name lenghth
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * SOURCE
*/

int_f
h5gmove_c(hid_t_f *loc_id, _fcd src_name, int_f *src_namelen, _fcd dst_name, int_f*dst_namelen)
/******/
{
    char *c_src_name = NULL, *c_dst_name = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_src_name = (char *)HD5f2cstring(src_name, (size_t)*src_namelen)))
        goto DONE;
    if(NULL == (c_dst_name = (char *)HD5f2cstring(dst_name, (size_t)*dst_namelen)))
        goto DONE;

    /*
     *  Call H5Gmove function
     */
    if(H5Lmove((hid_t)*loc_id, c_src_name, H5L_SAME_LOC, c_dst_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
        goto DONE;

    ret_value = 0;

DONE:
    if(c_src_name)
        HDfree(c_src_name);
    if(c_dst_name)
        HDfree(c_dst_name);
    return ret_value;
}

/****if* H5Gf/h5gmove2_c
 * NAME
 *  h5gmove2_c
 * PURPOSE
 *  Call H5Gmove2 to rename an object within an HDF5 file
 * INPUTS
 *  src_loc_id - identifier of file or group
 *  src_name - name of the original object relative to src_loc_id
 *  src_namelen - original name lenghth
 *  dst_loc_id - new location identifier
 *  dst_name - new name for the object relative to dst_loc_id
 *  dst_namelen - new name lenghth
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Wednesday, September 25, 2002
 *
 * SOURCE
*/

int_f
h5gmove2_c(hid_t_f *src_loc_id, _fcd src_name, int_f *src_namelen, hid_t_f *dst_loc_id, _fcd dst_name, int_f*dst_namelen)
/******/
{
    char *c_src_name = NULL, *c_dst_name = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_src_name = (char *)HD5f2cstring(src_name, (size_t)*src_namelen)))
        goto DONE;
    if(NULL == (c_dst_name = (char *)HD5f2cstring(dst_name, (size_t)*dst_namelen)))
        goto DONE;

    /*
     *  Call H5Gmove2 function
     */
    if(H5Lmove((hid_t)*src_loc_id, c_src_name, (hid_t)*dst_loc_id, c_dst_name, H5P_DEFAULT, H5P_DEFAULT) < 0)
        goto DONE;

    ret_value = 0;

DONE:
    if(c_src_name)
        HDfree(c_src_name);
    if(c_dst_name)
        HDfree(c_dst_name);
    return ret_value;
}

/****if* H5Gf/h5gget_linkval_c
 * NAME
 *  h5gget_linkval_c
 * PURPOSE
 *  Call H5Gget_linkval to return the name of object
 * INPUTS
 *  loc_id - identifier of file or group
 *  name - name of the object that symbolic link points to
 *  namelen - the name lenghth
 *  size - lenghth of retrurned value
 * OUTPUTS
 *  value - name to be returned
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * SOURCE
*/

int_f
h5gget_linkval_c(hid_t_f *loc_id, _fcd name, int_f *namelen, size_t_f *size,
    _fcd value)
/******/
{
    char *c_name = NULL;
    char *c_value = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /*
     *  Allocate buffer to hold name of the value
     */
    if(*size) c_value = (char *)HDmalloc((size_t)*size);
    if(c_value == NULL) {
                       HDfree(c_name);
                       return ret_value;
                       }

    /*
     *  Call H5Lget_val function
     */
    if(H5Lget_val((hid_t)*loc_id, c_name, c_value, (size_t)*size, H5P_DEFAULT) < 0)
         goto DONE;

    /*
     *  Convert C name to FORTRAN and place it in the given buffer
     */
    HD5packFstring(c_value, _fcdtocp(value), (size_t)*size);
    ret_value = 0;

DONE:
    if(c_value)
        HDfree(c_value);
    if(c_name)
        HDfree(c_name);
    return ret_value;
}

/****if* H5Gf/h5gset_comment_c
 * NAME
 *  h5gset_comment_c
 * PURPOSE
 *  Call H5Oset_comment_by_name to set comments for the specified object
 * INPUTS
 *  loc_id - identifier of file or group
 *  name - name of object whose comment is to be set or reset
 *  namelen - the name lenghth
 *  comment - the new comment
 *  commentlen - new comment lenghth
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * HISTORY
 *  Elena Pourmal
 * SOURCE
*/
int_f
h5gset_comment_c(hid_t_f *loc_id, _fcd name, int_f *namelen, _fcd comment,
    int_f *commentlen)
/******/
{
    char *c_name = NULL, *c_comment = NULL;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;
    if(NULL == (c_comment = (char *)HD5f2cstring(comment, (size_t)*commentlen)))
        goto DONE;

    /*
     *  Call H5Oset_comment_by_name function
     */
    if(H5Oset_comment_by_name((hid_t)*loc_id, c_name, c_comment, H5P_DEFAULT) < 0)
        goto DONE;
    ret_value = 0;

DONE:
    if(c_name)
        HDfree(c_name);
    if(c_comment)
        HDfree(c_comment);
    return ret_value;
}

/****if* H5Gf/h5gget_comment_c
 * NAME
 *  h5gget_comment_c
 * PURPOSE
 *  Call H5Oget_comment_by_name to retrieve comments for the specified object
 * INPUTS
 *  loc_id - identifier of file or group
 *  name - name of object whose comment is to be set or reset
 *  namelen - the name lenghth
 *  bufsize - at most bufsize characters
 *  comment - the new comment
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Mingshi Chen
 *  Friday, August 6, 1999
 * SOURCE
*/
int_f
h5gget_comment_c(hid_t_f *loc_id, _fcd name, int_f *namelen, size_t_f *bufsize,
    _fcd comment)
/******/
{
    char *c_name = NULL, *c_comment = NULL;
    size_t c_bufsize;
    int ret_value = -1;

    /*
     *  Convert Fortran name to C name
     */
    if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
        goto DONE;

    /*
     *  Allocate buffer to hold the comment
     */
    c_bufsize = (size_t)*bufsize;
    if(c_bufsize) {
        if(NULL == (c_comment = (char *)HDmalloc(c_bufsize + 1)))
            goto DONE;
    } /* end if */

    /*
     *  Call H5Oget_comment_by_name function
     */
    if(H5Oget_comment_by_name((hid_t)*loc_id, c_name, c_comment, c_bufsize, H5P_DEFAULT) < 0)
        goto DONE;

    /*
    *  Convert C name to FORTRAN and place it in the given buffer
    */
    HD5packFstring(c_comment, _fcdtocp(comment), c_bufsize);
    ret_value = 0;

DONE:
    if(c_name)
        HDfree(c_name);
    if(c_comment)
        HDfree(c_comment);
    return ret_value;
}

/****if* H5Gf/h5gcreate_anon_c
 * NAME
 *  h5gcreate_anon_c
 * PURPOSE
 *  Call H5Gcreate_anon
 * INPUTS
 *
 *  loc_id  - Location identifier
 *  gcpl_id - Group creation property list identifier
 *  gapl_id - Group access property list identifier
 *
 * OUTPUTS
 *  grp_id - group identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  February 15, 2008
 * SOURCE
*/
int_f
h5gcreate_anon_c(hid_t_f *loc_id, hid_t_f *gcpl_id, hid_t_f *gapl_id, hid_t_f *grp_id)
/******/
{

  int_f ret_value=0;          /* Return value */

  if ((*grp_id = (hid_t_f)H5Gcreate_anon((hid_t)*loc_id,(hid_t)*gcpl_id,(hid_t)*gapl_id)) < 0)
    HGOTO_DONE(FAIL);

done:
    return ret_value;
}

/****if* H5Gf/h5gget_create_plist_c
 * NAME
 *  h5gget_create_plist_c
 * PURPOSE
 *  Call H5Gget_create_plist
 * INPUTS
 *
 *  grp_id - group identifier
 *
 * OUTPUTS
 *  gcpl_id - Group creation property list identifier
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  February 15, 2008
 * SOURCE
*/
int_f
h5gget_create_plist_c(hid_t_f *grp_id, hid_t_f *gcpl_id )
/******/
{
  int_f ret_value=0; /* Return value */

  if ((*gcpl_id = (hid_t_f)H5Gget_create_plist((hid_t)*grp_id)) < 0)
    HGOTO_DONE(FAIL);

done:
    return ret_value;
}


/****if* H5Gf/h5gget_info_c
 * NAME
 *  h5gget_info_c
 * PURPOSE
 *  Call H5Gget_info
 * INPUTS
 *  group_id - Group identifier
 * OUTPUTS
 *
 *  storage_type - Type of storage for links in group:
 *                             H5G_STORAGE_TYPE_COMPACT: Compact storage
 *                             H5G_STORAGE_TYPE_DENSE: Indexed storage
 *                             H5G_STORAGE_TYPE_SYMBOL_TABLE: Symbol tables, the original HDF5 structure
 *
 *  nlinks - Number of links in group
 *  max_corder - Current maximum creation order value for group
 *  mounted - Whether group has a file mounted on it (0 = false, 1 = true)
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  February 15, 2008
 * HISTORY
 *
 *          - Added 'mounted' paramater
 *            M. Scot Breitenfeld
 *  July 16, 2008
 * SOURCE
*/
int_f
h5gget_info_c (hid_t_f *group_id, int_f *storage_type, int_f *nlinks, int_f *max_corder, int_f *mounted )
/******/
{

    int_f ret_value = 0;          /* Return value */
    H5G_info_t ginfo;

     /*
      * Call H5Gget_info function.
      */
    if(H5Gget_info((hid_t)*group_id,&ginfo) < 0)
      HGOTO_DONE(FAIL);

    /* Unpack the structure */

    *storage_type = (int_f)ginfo.storage_type;
    *nlinks = (int_f)ginfo.nlinks;
    *max_corder = (int_f)ginfo.max_corder;
    *mounted = 0;
    if(ginfo.mounted) *mounted = 1;

done:
    return ret_value;
}


/****if* H5Gf/h5gget_info_by_idx_c
 * NAME
 *  h5gget_info_by_idx_c
 * PURPOSE
 *  Call H5Gget_info_by_idx
 * INPUTS
 *
 *  loc_id - File or group identifier
 *  group_name - Name of group containing group for which information is to be retrieved
 *  group_namelen - name length
 *  index_type - Index type
 *  order - Order of the count in the index
 *  n - Position in the index of the group for which information is retrieved
 *  lapl_id - Link access property list
 * OUTPUTS
 *
 *  storage_type - Type of storage for links in group:
 *                             H5G_STORAGE_TYPE_COMPACT: Compact storage
 *                             H5G_STORAGE_TYPE_DENSE: Indexed storage
 *                             H5G_STORAGE_TYPE_SYMBOL_TABLE: Symbol tables, the original HDF5 structure
 *
 *  nlinks - Number of links in group
 *  max_corder - Current maximum creation order value for group
 *  mounted - Whether group has a file mounted on it (0 = false, 1 = true)
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  February 18, 2008
 * HISTORY
 *
 *          - Added 'mounted' paramater
 *            M. Scot Breitenfeld
 *  July 16, 2008
 * SOURCE
*/
int_f
h5gget_info_by_idx_c(hid_t_f *loc_id, _fcd group_name, size_t_f *group_namelen,
		      int_f *index_type, int_f *order, hsize_t_f *n, hid_t_f *lapl_id,
		      int_f *storage_type, int_f *nlinks, int_f *max_corder, int_f *mounted )
/******/
{
  char *c_group_name = NULL;          /* Buffer to hold group name C string */
  int_f ret_value = 0;          /* Return value */
  H5G_info_t ginfo;
  /*
   * Convert FORTRAN name to C name
   */
  if((c_group_name = HD5f2cstring(group_name, (size_t)*group_namelen)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Gget_info_by_idx function.
   */
  if(H5Gget_info_by_idx((hid_t)*loc_id,c_group_name, (H5_index_t)*index_type,(H5_iter_order_t)*order,(hsize_t)*n,
			&ginfo, (hid_t)*lapl_id) < 0)
    HGOTO_DONE(FAIL);

  /* Unpack the structure */

  *storage_type = (int_f)ginfo.storage_type;
  *nlinks = (int_f)ginfo.nlinks;
  *max_corder = (int_f)ginfo.max_corder;
  *mounted = 0;
  if(ginfo.mounted) *mounted = 1;

 done:
  if(c_group_name)
    HDfree(c_group_name);
  return ret_value;
}

/****if* H5Gf/h5gget_info_by_name_c
 * NAME
 *  h5gget_info_by_name_c
 * PURPOSE
 *  Call H5Gget_info_by_name
 * INPUTS
 *
 *  loc_id - File or group identifier
 *  group_name - Name of group containing group for which information is to be retrieved
 *  group_namelen - name length
 *  lapl_id - Link access property list
 * OUTPUTS
 *
 *  storage_type - Type of storage for links in group:
 *                             H5G_STORAGE_TYPE_COMPACT: Compact storage
 *                             H5G_STORAGE_TYPE_DENSE: Indexed storage
 *                             H5G_STORAGE_TYPE_SYMBOL_TABLE: Symbol tables, the original HDF5 structure
 *
 *  nlinks - Number of links in group
 *  max_corder - Current maximum creation order value for group
 *  mounted - Whether group has a file mounted on it (0 = false, 1 = true)
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  M. Scot Breitenfeld
 *  February 18, 2008
 * HISTORY
 *
 *          - Added 'mounted' paramater
 *            M. Scot Breitenfeld
 *  July 16, 2008
 * SOURCE
*/
int_f
h5gget_info_by_name_c(hid_t_f *loc_id, _fcd group_name, size_t_f *group_namelen, hid_t_f *lapl_id,
		       int_f *storage_type, int_f *nlinks, int_f *max_corder, int_f *mounted)
/******/
{
  char *c_group_name = NULL;          /* Buffer to hold group name C string */
  int_f ret_value = 0;          /* Return value */
  H5G_info_t ginfo;
  /*
   * Convert FORTRAN name to C name
   */
  if((c_group_name = HD5f2cstring(group_name, (size_t)*group_namelen)) == NULL)
    HGOTO_DONE(FAIL);

  /*
   * Call H5Gget_info_by_name function.
   */
  if(H5Gget_info_by_name((hid_t)*loc_id, c_group_name, &ginfo, (hid_t)*lapl_id) < 0)
    HGOTO_DONE(FAIL);

  /* Unpack the structure */

  *storage_type = (int_f)ginfo.storage_type;
  *nlinks = (int_f)ginfo.nlinks;
  *max_corder = (int_f)ginfo.max_corder;
  *mounted = 0;
  if(ginfo.mounted) *mounted = 1;

 done:
  if(c_group_name)
    HDfree(c_group_name);
  return ret_value;
}