summaryrefslogtreecommitdiffstats
path: root/src/H5R.c
blob: e6b09fcfa19878a2438ca4284792dff2954ab325 (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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/****************************************************************************
* NCSA HDF								   *
* Software Development Group						   *
* National Center for Supercomputing Applications			   *
* University of Illinois at Urbana-Champaign				   *
* 605 E. Springfield, Champaign IL 61820				   *
*									   *
* For conditions of distribution and use, see the accompanying		   *
* hdf/COPYING file.							   *
*									   *
****************************************************************************/

#ifdef RCSID
static char		RcsId[] = "@(#)$Revision$";
#endif

/* $Id$ */

#include <H5private.h>		/* Generic Functions */
#include <H5Iprivate.h>		/* ID Functions */
#include <H5Dprivate.h>		/* Datasets */
#include <H5Eprivate.h>		/* Error handling */
#include <H5Fprivate.h>		/* Files */
#include <H5Gprivate.h>		/* Groups */
#include <H5HGprivate.h>    /* Global Heaps */
#include <H5MMprivate.h>    /* Memory Management */
#include <H5Rprivate.h>		/* References */
#include <H5Sprivate.h>		/* Dataspaces */

/* Interface initialization */
#define PABLO_MASK	H5R_mask
#define INTERFACE_INIT	H5R_init_interface
static intn		interface_initialize_g = 0;
static herr_t		H5R_init_interface(void);

/* Static functions */
static herr_t H5R_create(void *ref, H5G_entry_t *loc, const char *name,
        H5R_type_t ref_type, H5S_t *space);
static hid_t H5R_dereference(H5D_t *dset, H5R_type_t ref_type, void *_ref);
static H5S_t * H5R_get_region(H5D_t *dset, H5R_type_t ref_type, void *_ref);


/*--------------------------------------------------------------------------
NAME
   H5R_init_interface -- Initialize interface-specific information
USAGE
    herr_t H5R_init_interface()
   
RETURNS
    Non-negative on success/Negative on failure
DESCRIPTION
    Initializes any interface-specific data or routines.

--------------------------------------------------------------------------*/
static herr_t
H5R_init_interface(void)
{
    FUNC_ENTER(H5R_init_interface, FAIL);

    /* Initialize the atom group for the file IDs */
    if (H5I_init_group(H5I_REFERENCE, H5I_REFID_HASHSIZE, H5R_RESERVED_ATOMS,
		       (H5I_free_t)NULL)<0) {
	HRETURN_ERROR (H5E_REFERENCE, H5E_CANTINIT, FAIL,
		       "unable to initialize interface");
    }

    FUNC_LEAVE(SUCCEED);
}


/*--------------------------------------------------------------------------
 NAME
    H5R_term_interface
 PURPOSE
    Terminate various H5R objects
 USAGE
    void H5R_term_interface()
 RETURNS
    void
 DESCRIPTION
    Release the atom group and any other resources allocated.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
     Can't report errors...
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void
H5R_term_interface(intn status)
{
    if (interface_initialize_g>0) {
	/* Free ID group */
	H5I_destroy_group(H5I_REFERENCE);
    }
    
    interface_initialize_g = status;
}


/*--------------------------------------------------------------------------
 NAME
    H5R_create
 PURPOSE
    Creates a particular kind of reference for the user
 USAGE
    herr_t H5R_create(ref, loc, name, ref_type, space)
        void *ref;          OUT: Reference created
        H5G_entry_t *loc;   IN: File location used to locate object pointed to
        const char *name;   IN: Name of object at location LOC_ID of object
                                    pointed to
        H5R_type_t ref_type;    IN: Type of reference to create
        H5S_t *space;       IN: Dataspace ID with selection, used for Dataset
                                    Region references.
        
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Creates a particular type of reference specified with REF_TYPE, in the
    space pointed to by REF.  The LOC_ID and NAME are used to locate the object
    pointed to and the SPACE_ID is used to choose the region pointed to (for
    Dataset Region references).
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5R_create(void *_ref, H5G_entry_t *loc, const char *name, H5R_type_t ref_type, H5S_t *space)
{
    H5G_stat_t sb;              /* Stat buffer for retrieving OID */
    herr_t ret_value = FAIL;

    FUNC_ENTER(H5R_create, FAIL);

    assert(_ref);
    assert(loc);
    assert(name);
    assert(ref_type>H5R_BADTYPE || ref_type<H5R_MAXTYPE);

    if (H5G_get_objinfo (loc, name, 0, &sb)<0)
        HGOTO_ERROR (H5E_REFERENCE, H5E_NOTFOUND, FAIL, "unable to stat object");

    switch(ref_type) {
        case H5R_OBJECT:
        {
            haddr_t addr;
            hobj_ref_t *ref=(hobj_ref_t *)_ref; /* Get pointer to correct type of reference struct */
            uint8_t *p;       /* Pointer to OID to store */

            /* Set information for reference */
            p=(uint8_t *)ref->oid;
            H5F_addr_pack(loc->file,&addr,&sb.objno[0]);
            H5F_addr_encode(loc->file,&p,&addr);
            break;
        }

        case H5R_DATASET_REGION:
        {
            haddr_t addr;
            H5HG_t hobjid;      /* Heap object ID */
            hdset_reg_ref_t *ref=(hdset_reg_ref_t *)_ref; /* Get pointer to correct type of reference struct */
            hssize_t buf_size;  /* Size of buffer needed to serialize selection */
            uint8_t *p;       /* Pointer to OID to store */
            uint8_t *buf;     /* Buffer to store serialized selection in */
            uintn heapid_found;  /* Flag for non-zero heap ID found */
            uintn u;        /* local index */

            /* Set up information for dataset region */

            /* Return any previous heap block to the free list if we are garbage collecting */
            if(loc->file->shared->access_parms->gc_ref) {
                /* Check for an existing heap ID in the reference */
                for(u=0, heapid_found=0; u<H5R_DSET_REG_REF_BUF_SIZE; u++)
                    if(ref->heapid[u]!=0) {
                        heapid_found=1;
                        break;
                    } /* end if */
                
                if(heapid_found!=0) {
/* Return heap block to free list */
                } /* end if */
            } /* end if */

            /* Zero the heap ID out, may leak heap space if user is re-using reference and doesn't have garbage collection on */
            HDmemset(ref->heapid,H5R_DSET_REG_REF_BUF_SIZE,0);

            /* Get the amount of space required to serialize the selection */
            if ((buf_size = H5S_select_serial_size(space)) < 0)
                HGOTO_ERROR(H5E_REFERENCE, H5E_CANTINIT, FAIL,
                  "Invalid amount of space for serializing selection");

            /* Increase buffer size to allow for the dataset OID */
            buf_size+=sizeof(haddr_t);

            /* Allocate the space to store the serialized information */
            if (NULL==(buf = H5MM_malloc(buf_size))) {
                HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
                       "memory allocation failed");
            }

            /* Serialize information for dataset OID */
            p=(uint8_t *)buf;
            H5F_addr_pack(loc->file,&addr,&sb.objno[0]);
            H5F_addr_encode(loc->file,&p,&addr);

            /* Serialize the selection */
            if (H5S_select_serialize(space,p) < 0)
                HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOPY, FAIL,
                  "Unable to serialize selection");

            /* Save the serialized buffer for later */
            if(H5HG_insert(loc->file,buf_size,buf,&hobjid)<0)
                HGOTO_ERROR(H5E_REFERENCE, H5E_WRITEERROR, FAIL,
                  "Unable to serialize selection");

            /* Serialize the heap ID and index for storage in the file */
            p=(uint8_t *)ref->heapid;
            H5F_addr_encode(loc->file,&p,&hobjid.addr);
            INT32ENCODE(p,hobjid.idx);

            /* Free the buffer we serialized data in */
            H5MM_xfree(buf);
            break;
        }

        case H5R_INTERNAL:
            HRETURN_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL,
                  "Internal references are not yet supported");

        case H5R_BADTYPE:
        case H5R_MAXTYPE:
        default:
            assert("unknown reference type" && 0);
            HRETURN_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL,
                  "internal error (unknown reference type)");
    } /* end switch */

    /* Return success */
    ret_value=SUCCEED;

done:
    FUNC_LEAVE(ret_value);
}   /* end H5R_create() */


/*--------------------------------------------------------------------------
 NAME
    H5Rcreate
 PURPOSE
    Creates a particular kind of reference for the user
 USAGE
    herr_t H5Rcreate(ref, loc_id, name, ref_type, space_id)
        void *ref;          OUT: Reference created
        hid_t loc_id;       IN: Location ID used to locate object pointed to
        const char *name;   IN: Name of object at location LOC_ID of object
                                    pointed to
        H5R_type_t ref_type;    IN: Type of reference to create
        hid_t space_id;     IN: Dataspace ID with selection, used for Dataset
                                    Region references.
        
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Creates a particular type of reference specified with REF_TYPE, in the
    space pointed to by REF.  The LOC_ID and NAME are used to locate the object
    pointed to and the SPACE_ID is used to choose the region pointed to (for
    Dataset Region references).
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5Rcreate(void *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t space_id)
{
    H5G_entry_t *loc = NULL;        /* File location */
    H5S_t	*space = NULL;          /* Pointer to dataspace containing region */
    herr_t ret_value = FAIL;

    FUNC_ENTER(H5Rcreate, FAIL);
    H5TRACE5("e","xisRti",ref,loc_id,name,ref_type,space_id);

    /* Check args */
    if(ref==NULL)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer");
    if (NULL==(loc=H5G_loc (loc_id)))
        HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a location");
    if (!name || !*name)
        HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name given");
    if(ref_type<=H5R_BADTYPE || ref_type>=H5R_MAXTYPE)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type");
    if(ref_type!=H5R_OBJECT && ref_type!=H5R_DATASET_REGION)
        HRETURN_ERROR (H5E_ARGS, H5E_UNSUPPORTED, FAIL, "reference type not supported");
    if (space_id!=(-1) && (H5I_DATASPACE!=H5I_get_type (space_id) || NULL==(space=H5I_object (space_id))))
        HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace");

    /* Create reference */
    if ((ret_value=H5R_create(ref,loc,name,ref_type,space))<0)
        HGOTO_ERROR (H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable to create reference");

done:
    FUNC_LEAVE(ret_value);
}   /* end H5Rcreate() */


/*--------------------------------------------------------------------------
 NAME
    H5R_dereference
 PURPOSE
    Opens the HDF5 object referenced.
 USAGE
    hid_t H5R_dereference(ref)
        H5D_t *dset;        IN: Dataset reference object is in.
        H5R_type_t ref_type;    IN: Type of reference
        void *ref;          IN: Reference to open.
        
 RETURNS
    Valid ID on success, Negative on failure
 DESCRIPTION
    Given a reference to some object, open that object and return an ID for
    that object.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Currently only set up to work with references to datasets
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static hid_t
H5R_dereference(H5D_t *dset, H5R_type_t ref_type, void *_ref)
{
    H5D_t *dataset;             /* Pointer to dataset to open */
    H5G_entry_t ent;            /* Symbol table entry */
    uint8_t *p;                 /* Pointer to OID to store */
    hid_t ret_value = FAIL;

    FUNC_ENTER(H5R_dereference, FAIL);

    assert(_ref);
    assert(ref_type>H5R_BADTYPE || ref_type<H5R_MAXTYPE);
    assert(dset);

    /* Initialize the symbol table entry */
    HDmemset(&ent,0,sizeof(H5G_entry_t));
    ent.type=H5G_NOTHING_CACHED;
    ent.file=H5D_get_file(dset);

    switch(ref_type) {
        case H5R_OBJECT:
        {
            hobj_ref_t *ref=(hobj_ref_t *)_ref; /* Only object references currently supported */
            /*
             * Switch on object type, when we implement that feature, always try to
             *  open a dataset for now
             */
            /* Get the object oid */
            p=(uint8_t *)ref->oid;
            H5F_addr_decode(ent.file,(const uint8_t **)&p,&(ent.header));
            break;
        } /* end case */

        case H5R_DATASET_REGION:
        {
            hdset_reg_ref_t *ref=(hdset_reg_ref_t *)_ref; /* Get pointer to correct type of reference struct */
            H5HG_t hobjid;  /* Heap object ID */
            uint8_t *buf;   /* Buffer to store serialized selection in */

            /* Get the heap ID for the dataset region */
            p=(uint8_t *)ref->heapid;
            H5F_addr_decode(ent.file,(const uint8_t **)&p,&(hobjid.addr));
            INT32DECODE(p,hobjid.idx);

            /* Get the dataset region from the heap (allocate inside routine) */
	    printf("%s: hobjid.addr=",FUNC);
	    H5F_addr_print(stdout,&hobjid.addr);
	    printf(", hobjid.idx=%d\n", hobjid.idx);
            if((buf=H5HG_read(ent.file,&hobjid,NULL))==NULL)
                HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, FAIL,
                  "Unable to read dataset region information");

            /* Get the object oid for the dataset */
            p=(uint8_t *)buf;
            H5F_addr_decode(ent.file,(const uint8_t **)&p,&(ent.header));

            /* Free the buffer allocated in H5HG_read() */
            H5MM_xfree(buf);
            break;
        } /* end case */

        case H5R_INTERNAL:
            HRETURN_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL,
                  "Internal references are not yet supported");

        case H5R_BADTYPE:
        case H5R_MAXTYPE:
        default:
            assert("unknown reference type" && 0);
            HRETURN_ERROR(H5E_REFERENCE, H5E_UNSUPPORTED, FAIL,
                  "internal error (unknown reference type)");
    } /* end switch */

    /* Open the dataset object */
    if ((dataset=H5D_open_oid(&ent)) == NULL) {
        HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL, "not found");
    }

    /* Create an atom for the dataset */
    if ((ret_value = H5I_register(H5I_DATASET, dataset)) < 0) {
        H5D_close(dataset);
        HRETURN_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL,
		      "can't register dataset");
    }

done:
    FUNC_LEAVE(ret_value);
}   /* end H5R_dereference() */


/*--------------------------------------------------------------------------
 NAME
    H5Rdereference
 PURPOSE
    Opens the HDF5 object referenced.
 USAGE
    hid_t H5Rdereference(ref)
        hid_t dataset;      IN: Dataset reference object is in.
        H5R_type_t ref_type;    IN: Type of reference to create
        void *ref;          IN: Reference to open.
        
 RETURNS
    Valid ID on success, Negative on failure
 DESCRIPTION
    Given a reference to some object, open that object and return an ID for
    that object.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
hid_t
H5Rdereference(hid_t dataset, H5R_type_t ref_type, void *_ref)
{
    H5D_t		   *dset = NULL;	/* dataset object */
    hid_t ret_value = FAIL;

    FUNC_ENTER(H5Rdereference, FAIL);
    H5TRACE3("i","iRtx",dataset,ref_type,_ref);

    /* Check args */
    if (H5I_DATASET != H5I_get_type(dataset) || NULL == (dset = H5I_object(dataset)))
        HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset");
    if(ref_type<=H5R_BADTYPE || ref_type>=H5R_MAXTYPE)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type");
    if(_ref==NULL)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer");

    /* Create reference */
    if ((ret_value=H5R_dereference(dset, ref_type, _ref))<0)
        HGOTO_ERROR (H5E_REFERENCE, H5E_CANTINIT, FAIL, "unable dereference object");

done:
    FUNC_LEAVE(ret_value);
}   /* end H5Rdereference() */


/*--------------------------------------------------------------------------
 NAME
    H5R_get_region
 PURPOSE
    Retrieves a dataspace with the region pointed to selected.
 USAGE
    H5S_t *H5R_get_region(ref)
        void *ref;        IN: Reference to open.
        
 RETURNS
    Pointer to the dataspace on success, NULL on failure
 DESCRIPTION
    Given a reference to some object, creates a copy of the dataset pointed
    to's dataspace and defines a selection in the copy which is the region
    pointed to.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static H5S_t *
H5R_get_region(H5D_t *dset, H5R_type_t ref_type, void *_ref)
{
    H5D_t *dataset;             /* Pointer to dataset to open */
    H5G_entry_t ent;            /* Symbol table entry */
    uint8_t *p;                 /* Pointer to OID to store */
    hdset_reg_ref_t *ref=(hdset_reg_ref_t *)_ref; /* Get pointer to correct type of reference struct */
    H5HG_t hobjid;  /* Heap object ID */
    uint8_t *buf;   /* Buffer to store serialized selection in */
    H5S_t *ret_value = NULL;

    FUNC_ENTER(H5R_get_region, NULL);

    assert(_ref);
    assert(ref_type==H5R_DATASET_REGION);
    assert(dset);

    /* Initialize the symbol table entry */
    HDmemset(&ent,0,sizeof(H5G_entry_t));
    ent.type=H5G_NOTHING_CACHED;
    ent.file=H5D_get_file(dset);

    /* Get the heap ID for the dataset region */
    p=(uint8_t *)ref->heapid;
    H5F_addr_decode(ent.file,(const uint8_t **)&p,&(hobjid.addr));
    INT32DECODE(p,hobjid.idx);

    /* Get the dataset region from the heap (allocate inside routine) */
    if((buf=H5HG_read(ent.file,&hobjid,NULL))==NULL)
        HGOTO_ERROR(H5E_REFERENCE, H5E_READERROR, NULL,
          "Unable to read dataset region information");

    /* Get the object oid for the dataset */
    p=(uint8_t *)buf;
    H5F_addr_decode(ent.file,(const uint8_t **)&p,&(ent.header));

    /* Open the dataset object */
    if ((dataset=H5D_open_oid(&ent)) == NULL) {
        HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, NULL, "not found");
    }

    /* Copy the dataspace object */
    if ((ret_value=H5D_get_space(dataset)) == NULL) {
        HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, NULL, "not found");
    }

/* Unserialize the selection */

    /* Free the buffer allocated in H5HG_read() */
    H5MM_xfree(buf);

/* Close the dataset we opened */


done:
    FUNC_LEAVE(ret_value);
}   /* end H5R_get_region() */


/*--------------------------------------------------------------------------
 NAME
    H5Rget_region
 PURPOSE
    Retrieves a dataspace with the region pointed to selected.
 USAGE
    hid_t H5Rget_region(ref)
        void *ref;        IN: Reference to open.
        
 RETURNS
    Valid ID on success, Negative on failure
 DESCRIPTION
    Given a reference to some object, creates a copy of the dataset pointed
    to's dataspace and defines a selection in the copy which is the region
    pointed to.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
hid_t
H5Rget_region(hid_t dataset, H5R_type_t ref_type, void *_ref)
{
    H5D_t *dset = NULL;     /* dataset object */
    H5S_t *space = NULL;    /* dataspace object */
    hid_t ret_value = FAIL;

    FUNC_ENTER(H5Rget_region, FAIL);
    H5TRACE3("i","iRtx",dataset,ref_type,_ref);

    /* Check args */
    if (H5I_DATASET != H5I_get_type(dataset) || NULL == (dset = H5I_object(dataset)))
        HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset");
    if(ref_type!=H5R_DATASET_REGION)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference type");
    if(_ref==NULL)
        HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid reference pointer");

    /* Get the dataspace with the correct region selected */
    if ((space=H5R_get_region(dset,ref_type,_ref))==NULL)
        HGOTO_ERROR (H5E_REFERENCE, H5E_CANTCREATE, FAIL, "unable to create dataspace");

    /* Atomize */
    if ((ret_value=H5I_register (H5I_DATASPACE, space))<0)
        HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace atom");

done:
    FUNC_LEAVE(ret_value);
}   /* end H5Rget_region() */