summaryrefslogtreecommitdiffstats
path: root/fortran/src/H5Ef.c
blob: c89ccd91c1ceacea094c85784a1c8824299a21d1 (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/****h* H5Ef/H5Ef
 * PURPOSE
 *   This file contains C stubs for H5E 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * 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* H5Ef/h5eclear_c
 * NAME
 *  h5eclear_c
 * PURPOSE
 *  Call H5Eclear to clear the error stack for the current thread
 * INPUTS
 *
 * OUTPUTS
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *  Wednesday, March 29, 2000
 * HISTORY
 *
 * SOURCE
*/
int_f
nh5eclear_c(hid_t_f *estack_id )
/******/
{
  int_f ret_value = 0;

  /*
   * Call H5Eclear function.
   */
  if(H5Eclear2((hid_t)*estack_id) < 0)
      HGOTO_DONE(FAIL)

done:
    return ret_value;
}

/****if* H5Ef/h5eprint_c1
 * NAME
 *  h5eprint_c1
 * PURPOSE
 *  Call H5Eprint to print the error stack in a default manner.
 * INPUTS
 *  name    - file name
 *  namelen - length of name
 * OUTPUTS
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *  Wednesday, March 29, 2000
 * HISTORY
 *  Bug fix: Added call to close the file with the error messages
 *  EP 11/26/01
 * SOURCE
*/
int_f
nh5eprint_c1(_fcd name, int_f* namelen)
/******/
{
    FILE *file = NULL;
    char *c_name = NULL;
    int_f ret_value = 0;

    if(NULL == (c_name = (char*)HD5f2cstring(name, (size_t)*namelen)))
        HGOTO_DONE(FAIL)
    if(NULL == (file = HDfopen(c_name, "a")))
        HGOTO_DONE(FAIL)

    /*
     * Call H5Eprint2 function.
     */
    if(H5Eprint2(H5E_DEFAULT, file) < 0)
        HGOTO_DONE(FAIL)

done:
    if(file)
        HDfclose(file);
    if(c_name)
        HDfree(c_name);

    return ret_value;
}

/****if* H5Ef/h5eprint_c2
 * NAME
 *  h5eprint_c2
 * PURPOSE
 *  Call H5Eprint to print the error stack to stderr
 *  in a default manner.
 * INPUTS
 *
 * OUTPUTS
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *  Wednesday, March 29, 2000
 *
 * SOURCE
*/
int_f
nh5eprint_c2(void)
/******/
{
    int_f ret_value = 0;

    /*
     * Call H5Eprint2 function.
     */
    if(H5Eprint2(H5E_DEFAULT, NULL) < 0)
        HGOTO_DONE(FAIL)

done:
    return ret_value;
}

/****if* H5Ef/h5eget_major_c
 * NAME
 *  h5eget_major_c
 * PURPOSE
 *  Get a character string describing an error specified by a
 *  major error number.
 * INPUTS
 *  error_no - Major error number
 * OUTPUTS
 *  name - character string describing the error
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *  Wednesday, March 29, 2000
 * HISTORY
 *
 * SOURCE
*/
int_f
nh5eget_major_c(int_f* error_no, _fcd name, size_t_f* namelen)
/******/
{
    char *c_name = NULL;
    size_t c_namelen = (size_t)*namelen;
    int_f ret_value = 0;

    if(c_namelen > 0) 
        c_name = (char *)HDmalloc(c_namelen + 1);

    if(!c_name)
        HGOTO_DONE(FAIL)

    /*
     * Call H5Eget_msg function.
     */
    H5Eget_msg((hid_t)*error_no, NULL, c_name, c_namelen);
    HD5packFstring((char*)c_name, _fcdtocp(name), c_namelen);
    if(!HDstrcmp(c_name, "Invalid major error number"))
        HGOTO_DONE(FAIL)

done:
    if(c_name)
        HDfree(c_name);

    return ret_value;
}

/****if* H5Ef/h5eget_minor_c
 * NAME
 *  h5eget_minor_c
 * PURPOSE
 *  Get a character string describing an error specified by a
 *  minor error number.
 * INPUTS
 *  error_no - Major error number
 * OUTPUTS
 *  name - character string describing the error
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Xiangyang Su
 *  Wednesday, March 29, 2000
 * HISTORY
 *
 * SOURCE
*/
int_f
nh5eget_minor_c(int_f* error_no, _fcd name, size_t_f* namelen)
/******/
{
    char *c_name = NULL;
    size_t c_namelen = (size_t)*namelen;
    int_f ret_value = 0;

    if(c_namelen > 0) 
        c_name = (char *)HDmalloc(c_namelen + 1);

    if(!c_name)
        HGOTO_DONE(FAIL)

    /*
     * Call H5Eget_msg function.
     */
    H5Eget_msg((hid_t)*error_no, NULL, c_name, c_namelen);
    HD5packFstring((char *)c_name, _fcdtocp(name), c_namelen);
    if(!HDstrcmp(c_name, "Invalid minor error number"))
        HGOTO_DONE(FAIL)

done:
    if(c_name)
        HDfree(c_name);

    return ret_value;
}

/****if* H5Ef/h5eset_auto_c
 * NAME
 *  h5eset_auto_c
 * PURPOSE
 *  Call H5Eset_auto to turn automatic error printing on or off.
 * INPUTS
 *  printflag - flag to turn automatic error printing on or off.
 * OUTPUTS
 *
 * RETURNS
 *  0 on success, -1 on failure
 * AUTHOR
 *  Elena Pourmal
 *  Friday, November 17, 2000
 * HISTORY
 *  Major bug fix: Function never disabled printing.
 * SOURCE
*/
int_f
nh5eset_auto_c(int_f* printflag)
/******/
{
    herr_t status = -1;
    int_f ret_value = 0;

    if(*printflag == 1)
        status = H5Eset_auto2(H5E_DEFAULT, (H5E_auto2_t)H5Eprint2, stderr);
    else if(*printflag == 0)
        status = H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
    if(status < 0)
        HGOTO_DONE(FAIL)

done:
    return ret_value;
}


/****if* H5Ef/h5eset_auto2_c
 * NAME
 *   h5eset_auto2_c
 * PURPOSE
 *   Calls H5Eset_auto2
 * INPUTS
 *   estack_id    - Error stack identifier.
 *   func 	 - Function to be called upon an error condition.
 *   client_data - Data passed to the error function.
 *   
 * RETURNS
 *   0 on success, -1 on failure
 * AUTHOR
 *   M. Scot Breitenfeld
 *   July 22, 2009
 * SOURCE
*/

int_f
h5eset_auto2_c(int_f *printflag, hid_t_f *estack_id, H5E_auto2_t func, void *client_data)
/******/
{
  int ret_val = -1;
  herr_t status = -1;

  if (*printflag == 1 && *estack_id == -1)
    status = H5Eset_auto2(H5E_DEFAULT, (H5E_auto2_t)H5Eprint2, stderr);
  else if (*printflag == 1)
    status = H5Eset_auto2((hid_t)*estack_id, func, client_data);
  else if (*printflag == 0)
    status = H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
  if (status >= 0) ret_val = 0;

  return ret_val;
}