There are three ways to check a reference number for an object:
11.7.1 Determining a Reference Number for the Last Object Accessed: DF*lastref and DF*writeref
There are two methods of obtaining a reference number through the use of a DF*lastref call. The first approach is to obtain and store the reference number of an object immediately after the object is created:
Most HDF interfaces provide one routine that assigns a specified reference number to a data object and another routine that returns the reference number for the last data object accessed. (See Table 11H.) However, the SD interface doesn't. Also, the DFAN annotation doesn't include a DF*lastref routine.
Although DF*writeref calls are designed to assign specific reference numbers, they are not recommended for general use because there is no protection against reassigning an existing reference number and overwriting data. In general, it is better to determine a reference number for a data object by calling DF*lastref immediately after reading or writing a data object.
filename
, which is the name of the file that contains the data object, and ref
, which is the reference number for the next data object read operation.TABLE 11H - List and Descriptions of the DF*writeref and DF*lastref Routines
To create a list of reference numbers and their labels for a given tag, the following routines should be called:
C: num_refs = Hnumber(file_id, tag);
ref_buf = HDmalloc(sizeof(uint16*)*num_refs);
max_lab_len = 16;
label_buf = HDmalloc(max_lab_len * num_refs);
start_pos = 0;
num_of_refs = DFANlablist(filename, tag, ref_buf, label_buf,
num_refs, max_lab_len,
start_pos);
FORTRAN: num_refs = hnumber(file_id, tag)
max_lab_len = 16
start_pos = 0
num_of_refs = dallist(filename, tag, ref_buf, label_buf,
num_refs, max_lab_len, start_pos)
Hnumber determines how many objects with the specified tag are in a file. It is described in Chapter 2, HDF Fundamentals.
DFANlablist has seven parameters:
filename
, tag
, ref_list
, label_buf
, num_refs
, max_lab_len
, and start_pos
. The filename
parameter specifies the name of the file to search and tag
specifies the search tag to use when creating the reference and label list. The ref_buf
and label_buf
parameters are buffers used to store the reference numbers and labels associated with tag
. The num_ref
parameter specifies the length of the reference number list and the max_lab_len
parameter specifies the maximum length of a label. The start_pos
parameter specifies the first label to read. For instance, if start_pos
has a value of 1
all labels will be read; if it has a value of 4
, all but the first three labels will be read. ref_list
and label_list
constitute a directory of all objects and their labels for a given tag. The contents of label_list
can be displayed to show all of the labels for a given tag or it can be searched to find the reference number of a data object with a certain label. Once the reference number for a given label is found, the corresponding data object can be accessed by invoking other HDF routines. Therefore, this routine provides a mechanism for direct access to data objects in HDF files.TABLE 11I - DFANlablist Parameter List
DFS_MAXLEN
definition is located in the "hlimits.h" include file.C version
11.7.3 Locate an Object by Its Tag and Reference Number: Hfind
Instead of using DFANlablist to create a list of reference numbers to search, HDF provides a general search routine called Hfind. Hfind is described in Chapter 2, HDF Fundamentals.