home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / graphics.formats / hdf / NCSA_HDF / HDF.6.ascii.Z / HDF.6.ascii
Encoding:
Text File  |  1991-09-24  |  19.9 KB  |  535 lines

  1. 6.1NCSA HDF Calling Interfaces and Utilities
  2.  
  3. General Purpose HDF Routines6.1
  4.  
  5. National Center for Supercomputing Applications
  6.  
  7. November 1989
  8.  
  9.  
  10.  
  11. 6.1NCSA HDF Calling Interfaces and Utilities
  12.  
  13. General Purpose HDF Routines6.1
  14.  
  15. National Center for Supercomputing Applications
  16.  
  17. November 1989
  18.  
  19. 6.1NCSA HDF Calling Interfaces and Utilities
  20.  
  21. General Purpose HDF Routines6.1
  22.  
  23. National Center for Supercomputing Applications
  24.  
  25. November 1989
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. 6.1NCSA HDF Calling Interfaces and Utilities
  33.  
  34. General Purpose HDF Routines6.1
  35.  
  36. National Center for Supercomputing Applications
  37.  
  38. November 1989
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. Chapter 6General Purpose HDF Routines
  49.  
  50.  
  51.  
  52. Chapter Overview
  53. Introduction
  54. Header Files
  55. Opening and Closing Files
  56. Finding Tags, Refs, and Element Lengths
  57. Storing and Retrieving Entire Data Elements
  58. Reading or Writing Part of a Data Element
  59. Manipulating Data Descriptors (DDs)
  60. Miscellaneous
  61.  
  62. Chapter Overview
  63.  
  64. The following chapter is a reference to the set of general purpose low-level routines used when working with HDF files. Note that if you are using a higher level HDF interface, such as RIS8, you probably do not need to use these low-level routines.
  65.  
  66.  
  67. Introduction
  68.  
  69. At times you may need a lower level of access to HDF files than that provided by more application-oriented interfaces such as RIS8 and SDS. The routines described in this chapter enable you to build and manipulate HDF files of any type, including those of your own invention. All HDF applications developed at NCSA use these routines as their basic building blocks.
  70.  
  71. NOTE:  If you are using an HDF package such as RIS8, you probably do not need to use any of these routines. In fact if you use some of these lower level routines while simultaneously accessing a file with the higher level interfaces, the higher level routines may not function properly.
  72.  
  73. In order to understand how these routines work, it is important to understand the underlying structure of all HDF files. Detailed information about the basic HDF structure and how it works can be found in NCSA HDF Specifications, which may be obtained by contacting NCSA's Software Tools Group at the address listed on the README page at the beginning of this manual.
  74.  
  75.  
  76. Table 6.1 lists the long and short names and the functions of the general purpose routines currently contained in the HDF library. The following sections provide descriptions and examples of these calling routines.
  77.  
  78. Table 6.1General Purpose Routines in the HDF Library
  79. Long NameShort NameFunction
  80.  
  81. DFopenprovides an access path to the file named in filename with the access given in access. 
  82.  
  83. DFcloseupdates the DD blocks, then closes the access path to the file referred to by dfile.
  84.  
  85. DFsetfinddfsfindinitializes searches for elements using tags or reference numbers.
  86.  
  87. DFfinddffindlocates the data descriptor needed for the next read from the file.
  88.  
  89.  
  90.  
  91. Table 6.1General Purpose Routines in the HDF Library(Continued)
  92. Long NameShort NameFunction
  93.  
  94.  
  95. DFgetelementdfgetextracts the data referred to by the tag/ref  and places the data in the array storage.
  96.  
  97. DFputelementdfputadds or replaces elements in dfile.
  98.  
  99. DFaccessinititiates a read or write on the data element with the specified tag/ref combination. 
  100.  
  101. DFreadreads a portion of a data element.
  102.  
  103. DFwriteappends data to a data element.
  104.  
  105. DFseeksets the read pointer to an offset within a data element.
  106.  
  107. DFupdatewrites out the DD blocks necessary to update the file.
  108.  
  109. DFdupgenerates a DD whose offset and length are the same as those of another tag/ref.
  110.  
  111. DFdeldeletes a tag/ref from the list of DDs.
  112.  
  113. DFerrnoreports the value of DFerror.
  114.  
  115. DFishdftells if a file is an HDF file.
  116.  
  117. DFnewrefgenerates an unused reference number.
  118.  
  119. DFstatprovides status information about an HDF file.
  120.  
  121.  
  122. Header Files
  123.  
  124. You may need to include a header file if your program uses special HDF declarations or definitions. There are two header files, one for FORTRAN and one for C, that apply to the general purpose I/O routines listed here:
  125.  
  126. ÑdfF.h contains the declarations and definitions that are used by FORTRAN routines.
  127.  
  128. Ñdf.h contains the declarations and definitions that are used by C routines.
  129.  
  130.  
  131. For example, if your program uses mnemonics for tags, the corresponding numerical values for the tags can be found in dfF.h (FORTRAN) or df.h (C). The contents of dfF.h and df.h are listed in Appendix B.
  132.  
  133. Although the use of header files is always permitted in C programs, it is generally not permitted in FORTRAN. It is, however, sometimes available as an option in FORTRAN. For example, on UNIX systems, the macro processors m4 and cpp let your compiler include and preprocess header files. If this or a similar capability is not available, you may have to copy whatever declarations, definitions, or values you need from dfF.h into your program code.
  134.  
  135.  
  136. Opening and Closing Files
  137.  
  138. DFopen
  139. FORTRAN:
  140. INTEGER FUNCTION DFopen(filename, access, defDDs)
  141.  
  142. CHARACTER*64 filename-name of file to be opened
  143. INTEGER access-type of access
  144. INTEGER defDDs-number of data descriptors to
  145. allocate per block
  146.  
  147. C:
  148. DF *DFopen(filename, access, defDDs)
  149.  
  150. char*filename;/* name of file to be opened */
  151. intaccess;/* type of access */
  152. intdefDDs;/* number of data descriptors to allocate per block*/
  153.  
  154. Purpose:  To provide an access path to the file named in filename with the access given in access.
  155.  
  156. Return value:  An integer (FORTRAN) or pointer (C) that identifies the file access path. If the call succeeds, the return value is positive. If the call fails, the return value is 0 (FORTRAN) or NULL (C).
  157.  
  158. DFopen also reads into memory all of the DD blocks in the file.
  159.  
  160. Values allowed for access are DFACC_READ for read only, DFACC_WRITE for write only, DFACC_ALL for read and write, and DFACC_CREATE for create or overwrite. If the file must be created or extended, defDDs specifies the number of data descriptors (DDs) to be allocated per DD block. If defDDs ▓ 0, the number of data descriptors is set to the machine default.
  161.  
  162. NOTE:  In the current implementation, only one file can be open at a time.
  163.  
  164.  
  165. DFclose
  166. FORTRAN:
  167. INTEGER FUNCTION DFclose(dfile)
  168.  
  169. INTEGERdfile-identifier of file access path
  170.  
  171. C:
  172. int DFclose(dfile)
  173.  
  174. DF *dfile;/* file access path */
  175.  
  176. Purpose:  To update the DD blocks, then close the access path to the file referred to by dfile.
  177.  
  178. Return value:  0 on success and -1 on failure.
  179.  
  180. NOTE:  If the contents of a file have been changed, it is important to call DFclose to ensure that the DD blocks are written to the file. (To cause all DD blocks to be written to the file without also closing the file, see DFupdate.)
  181.  
  182.  
  183. Finding Tags, Refs, and Element Lengths
  184.  
  185. The routines DFsetfind and DFfind are for locating data descriptors in a file. Given the tag and ref of a data object, DFsetfind initializes a search for the object's data descriptor, and DFfind returns information from the data descriptor about the data. This information is necessary for accessing the actual data.
  186.  
  187. DFsetfind and DFfind also make it possible to locate elements without previous knowledge of their tags or reference numbers (or both). For example, if you know that several instances of a given tag are in a file, but do not know the reference numbers, you can use these routines to find the reference numbers and their corresponding data descriptors. One call to DFsetfind, followed by successive calls to DFfind, lets you step through all of the refs that go with the tag.
  188.  
  189. DFsetfind and DFfind provide a kind of "seeking" capability, where the objective is to seek to a particular data descriptor in the data descriptor block, rather than to seek to a byte offset in the file.
  190.  
  191.  
  192. DFsfind (FORTRAN) and DFsetfind(C)
  193. FORTRAN:
  194. INTEGER FUNCTION DFsfind(dfile, tag, ref)
  195.  
  196. INTEGERdfile-identifier of file access path
  197. INTEGERtag, ref-tag and ref to be located
  198.  
  199. C:
  200. int DFsetfind(dfile, tag, ref)
  201.  
  202. DF*dfile;/* file access path */
  203. uint16tag, ref;/* tag and ref to be located */
  204.  
  205. Purpose:  To initialize searches for elements using tags or reference numbers. 
  206.  
  207. Return value:  0 on success and -1 on failure.
  208.  
  209. DFsetfind initializes any search for elements with a given tag or ref by setting tag and ref values in the file pointer, dfile. 
  210.  
  211. The parameder ref may be replaced by the "wildcard" flag, DFREF_WILDCARD, which indicates that the search by DFfind is to begin with the first ref in the file that matches the tag. Subsequent calls to DFfind return the refs for the specified tag in ascending order.
  212.  
  213. Similarly, the tag parameter may be DFTAG_WILDCARD, indicating that DFfind is to begin with the first tag that occurs with the specified ref.
  214.  
  215. If both tag and ref are wildcards, DFfind will return the tags and reference numbers in ascending order with reference numbers as the primary field.
  216.  
  217.  
  218. DFfind
  219. FORTRAN:
  220. INTEGER FUNCTION DFfind(dfile, tag, ref, len)
  221.  
  222. INTEGERdfile-identifier of file access path
  223. INTEGERtag, ref-tag/ref of dataINTEGERlen-number of bytes of data 
  224.  
  225. C:
  226. int DFfind(dfile, ptr)
  227.  
  228. DF *dfile;/* file access path */
  229. struct DFdesc *ptr/* pointer to data descriptor for data */
  230.  
  231. Purpose:  To locate the data descriptor needed for the next read from the file.
  232.  
  233. Return value:  0 on success; if there are no more elements which match the pattern, a negative number is returned and tag and ref are set to zero.
  234.  
  235. The C version of this program returns a pointer to the actual data descriptor for the tag/ref that have be set. Since FORTRAN cannot, in general, support pointers or structures, the FORTRAN version returns in three separate variables the tag, ref, and length from the data descriptor.
  236.  
  237. In addition to the values that are returned, DFfind updates the file structure pointed to by dfile to indicate that the data object that has been located is the "current" one.
  238.  
  239. If DFsetfind has set specific tag and ref values, DFfind prepares the HDF system to access the corresponding object in the file. If ref were the flag DFREF_WILDCARD, then DFfind prepares the system to access the next ref for the specified tag. Similarly, if the tag was the flag DFREF_WILDCARD, then DFfind prepares the system to access the next tag for the specified ref.
  240.  
  241.  
  242. Storing and Retrieving Entire Data Elements
  243.  
  244. There are two sets of routines for reading and writing data elements. DFput (DFputelement) and DFget (DFgetelement), described here, store and retrieve entire elements. A second set of routines may be used if it is desired to access only part of a data element at a time. These routines are covered in the next section.
  245.  
  246.  
  247. DFget (FORTRAN) and DFgetelement (C)
  248. FORTRAN:
  249. INTEGER FUNCTION DFget(dfile, tag, ref, storage)
  250.  
  251. INTEGERdfile-identifier of file access path
  252. INTEGERtag, ref-tag and ref of data to be retrieved
  253. CHARACTER*1storage(*)-array for storing incoming data
  254.  
  255. C:
  256. int DFgetelement(dfile, tag, ref, ptr)
  257.  
  258. DF*dfile;/* file access path */
  259. uint16tag, ref;/* tag and ref of data to be retrieved */
  260. unsigned char ptr;/* pointer to space for storing incoming data */
  261.  
  262. Purpose:  To extract the data referred to by the tag/ref and place the data in the array storage.
  263.  
  264. Return value:  If DFget succeeds, the return value is the number of bytes read. If it fails, -1 is returned.
  265.  
  266.  
  267. DFput (FORTRAN) and DFputelement (C)
  268. FORTRAN:
  269. INTEGER FUNCTION DFput(dfile, tag, ref, storage, len)
  270.  
  271. INTEGERdfile-identifier of file access path
  272. INTEGERtag, ref-tag and ref of data to store
  273. INTEGERlen-number of bytes of data to store
  274. CHARACTER*1storage(len)- array with data to be stored
  275.  
  276. C:
  277. int DFputelement(dfile, tag, ref, ptr, len)
  278.  
  279. DF*dfile;/* file access path */
  280. uint16tag, ref;/* tag and ref of data to be retrieved */
  281. char*ptr;/* pointer to data to be stored */
  282. int32len;/* number of bytes of data to be stored */
  283.  
  284. Purpose:  To add or replace elements in dfile. 
  285.  
  286. Return value:  If DFputelement succeeds, the return value is the number of bytes read. If it fails, -1 is returned.
  287.  
  288. The first len bytes in the array storage are written to the file with tag/ref referring to them.
  289.  
  290. NOTE:  Since there can be no two elements with the same tag and reference numbers, any call with a tag/ref combination that duplicates an existing tag/ref replaces the previous element.
  291.  
  292. NOTE:  The corresponding tag entry in the DD block is not updated until DFclose or DFupdate is called.
  293.  
  294.  
  295. Reading or Writing Part of a Data Element
  296.  
  297. The second set of routines for reading and writing data elements makes it possible to read or write all or part of a data element, in contrast to DFput and DFget, described in the previous section, which can only read or write entire elements.
  298.  
  299.  
  300. DFaccess
  301. FORTRAN:
  302. INTEGER FUNCTION DFaccess(dfile, tag, ref, access)
  303.  
  304. INTEGERdfile-identifier of file access path
  305. INTEGERtag, ref-tag and ref of data to be accessed
  306. CHARACTER*1access-access mode
  307.  
  308. C:
  309. int DFaccess(dfile, tag, ref, access)
  310.  
  311. DF*dfile;/* file access path */
  312. uint16tag, ref;/* tag and ref of data to access */
  313. char*access;/* access mode */
  314.  
  315. Purpose:  To initiate a read or write on the data element with the specified tag/ref combination. For read, write, or append access, respectively, access is 'r', 'w', or 'a' (FORTRAN) and "r", "w", or "a" (C).
  316.  
  317. Return value:  0 on success; -1 on failure.
  318.  
  319. DFaccess must be invoked before the first DFread or DFwrite operation can be performed. It checks that the access mode is valid and moves to the first byte of the desired element in the file. If append access is specified, subsequent writes are appended to the end of the existing data.
  320.  
  321.  
  322. DFread
  323. FORTRAN:
  324. INTEGER FUNCTION DFread(dfile, data, len)
  325.  
  326. INTEGERdfile-identifier of file access path
  327. INTEGER len-number of bytes to read
  328. CHARACTER*1data(len)-array that will hold data
  329.  
  330. C:
  331. int DFread(dfile, data, len)
  332.  
  333. DF*dfile;/* file access path */
  334. char*data;/* array that will hold data */
  335. uint16len;/* number of bytes to read */
  336.  
  337. Purpose:  To read a portion of a data element. 
  338.  
  339. Return value:  If DFread is able to read any bytes, it returns the number of bytes read. If it is at the end of the element before the read occurs, it returns zero. On failure, it returns -1.
  340.  
  341. DFread starts at the last position left by a DFaccess, DFread or DFseek command and reads into the array data; i.e., any data that remains in the element up to len bytes. It fails if the DFaccess mode was not 'r' ("r").
  342.  
  343.  
  344. DFwrite
  345. FORTRAN:
  346. INTEGER FUNCTION DFwrite(dfile, data, len)
  347.  
  348. INTEGER dfile-identifier of file access path
  349. INTEGERlen-number of bytes to write
  350. CHARACTER*1data(len)-array with data to be written
  351.  
  352. C:
  353. int DFwrite(dfile, data, len)
  354.  
  355. DF*dfile;/* file access path */
  356. char*data;/* array with data to be written */
  357. uint16len;/* number of bytes to write */
  358.  
  359. Purpose:  To append data to a data element. 
  360.  
  361. Return value:  Number of bytes written on success; negative on failure.
  362.  
  363. DFwrite starts at the last position left by a DFaccess or DFwrite command and writes up to len bytes, then leaves the write pointer at the end of the element.
  364.  
  365. DFwrite fails if the DFaccess mode is not 'w' or 'a' ("w" or "a").
  366.  
  367. NOTE:  The corresponding tag entry in the DD block is not updated until DFclose or DFupdate is called. 
  368.  
  369.  
  370. DFseek
  371. FORTRAN:
  372. INTEGER FUNCTION DFseek(dfile, offset)
  373.  
  374. INTEGERdfile-identifier of file access path
  375. INTEGERoffset-offset within data element to seek to
  376.  
  377. C:
  378. int32 DFseek(dfile, offset)
  379.  
  380. DF*dfile;/* file access path */
  381. int32offset;/* offset within data to seek to */
  382.  
  383. Purpose:  To set the read pointer to an offset within a data element. 
  384.  
  385. Return value:  On success, number of bytes from the beginning of the element to the new pointer position; on failure, negative.
  386.  
  387. DFseek tries to count offset number of bytes from the beginning of the element and set the read pointer there. The next time DFread is called, the read occurs from the new position.
  388.  
  389. If offset is such that the seek goes out of the range of the data item, an error is reported.
  390.  
  391. NOTE:  DFseek is only valid when used in conjunction with a DFread. It should not be used to position a write operation.
  392.  
  393.  
  394. Manipulating Data Descriptors (DDs) 
  395.  
  396. These routines perform operations on DDs without doing anything with the data to which the DDs refer.
  397.  
  398.  
  399. DFupdate
  400. FORTRAN:
  401. INTEGER FUNCTION DFupdate(dfile)
  402.  
  403. INTEGERdfile-identifier of file access path
  404.  
  405. C:
  406. int DFupdate(dfile)
  407.  
  408. DF*dfile;/* file access path */
  409.  
  410. Purpose:  To write out the DD blocks necessary to update the file. 
  411.  
  412. Return value:  0 on success; -1 on failure.
  413.  
  414. All data elements that have been written or partially written to the file are given valid DDs.
  415.  
  416. DFupdate is useful because HDF does not automatically write DDs to a file when the corresponding data is written out. Instead, it keeps all of the DDs in a special structure in primary memory, then writes them all out when DFclose is called.
  417.  
  418. If a crash occurs after data has been written out to a file but before the file is closed, changes that have been made to the file can be lost. If a DFupdate is performed immediately after a write, then the changes made by the write are not lost because both the DDs and the corresponding data have been stored in the file.
  419.  
  420.  
  421. DFdup
  422. FORTRAN:
  423. INTEGER FUNCTION DFdup(dfile, tag, ref, otag, oref)
  424.  
  425. INTEGERdfile-identifier of file access path
  426. INTEGERtag, ref-new tag and ref to point to old data
  427. INTEGERotag, oref-tag & ref that already point to data
  428.  
  429. C:
  430. int DFdup(dfile, tag, ref, otag, oref)
  431.  
  432. DF*dfile;/* file access path */
  433. uint16 tag, ref;/* new tag and ref to point to old data */
  434. uint16otag, oref;/* tag & ref that already point to data */
  435.  
  436. Purpose:  To generate a DD whose offset and length are the same as those of another tag/ref.
  437.  
  438. Return value:  0 on success and a negative error indicator if otag/oref is not present in the file.
  439.  
  440. Sometimes it is desirable to have more than one DD point to a single data element. In such cases, the offset and length fields are identical for two or more DDs. DFdup is used to generate new references to data that are already referenced from somewhere else.
  441.  
  442. DFdup creates a new tag/ref (tag/ref) that points to the same data as an old tag/ref (otag/oref). If the new tag/ref combination already exists in the file, then the offset and length are changed to their new values.
  443.  
  444. WARNING:  When a data element that is referenced from several places is modified, there is a danger that duplicate references to that data no longer point to the correct data. For instance, when a data element is moved, HDF does not automatically change all prior references to that data to point to the data in its new location.
  445.  
  446.  
  447. DFdel
  448. FORTRAN:
  449. INTEGER FUNCTION DFdel(dfile, tag, ref)
  450.  
  451. INTEGERdfile-identifier of file access path
  452. INTEGERtag, ref-tag and ref of data to be deleted
  453.  
  454. C:
  455. int DFdel(dfile, tag, ref)
  456.  
  457. DF*dfile;/* file access path */
  458. uint16 tag, ref;/* tag and ref of data to be deleted */
  459.  
  460. Purpose:  To delete a tag/ref from the list of DDs.
  461.  
  462. Return value:  0 on success; -1 on failure.
  463.  
  464. The data to which this DD points is not affected by DFdel, but is reclaimed when the file is compacted. 
  465.  
  466. If there are multiple references to this data, then the other references remain intact, and compaction does not affect the data itself. If there are no other references to a data element, DFdel may implicitly leave the data without any reference, making the data inaccessible.
  467.  
  468.  
  469. Miscellaneous
  470.  
  471. DFerrno
  472. FORTRAN:
  473. INTEGER FUNCTION DFerrno()
  474.  
  475. C:
  476. int DFerrno()
  477.  
  478. Purpose:  To report the value of DFerror.
  479.  
  480. Return value:  The value of DFerror.
  481.  
  482.  
  483. DFishdf
  484. FORTRAN:
  485. INTEGER FUNCTION DFishdf(filename)
  486.  
  487. integer filename- name of HDF file
  488.  
  489. C:
  490. int DFishdf(filename)
  491.  
  492. DF  *filename/* name of HDF file */
  493.  
  494. Purpose:  To tell if a file is an HDF file.
  495.  
  496. Return value:  0 if it is an HDF file; -1 if not.
  497.  
  498.  
  499. DFnewref
  500. FORTRAN:
  501. INTEGER FUNCTION DFnewref(dfile)
  502.  
  503. INTEGER dfile- pointer to open HDF file
  504.  
  505. C:
  506. uint16 DFnewref(dfile)
  507.  
  508. DF  *dfile/* pointer to open HDF file */
  509.  
  510. Purpose:  To get an unused reference number.
  511.  
  512. Return value:  Unused ref number if successful; 0 on failure.
  513.  
  514. This routine is useful  when you want to add a data element to an HDF file and you need a unique reference number.  The value returned is a ref which is not used with any tag, except possibly DFTAG_MT.
  515.  
  516.  
  517. DFstat
  518. FORTRAN:
  519. INTEGER FUNCTION DFstat(dfile, dfinfo)
  520.  
  521. INTEGER dfile- pointer to an open HDF file 
  522. INTEGER dfinfo- pointer to information on file 
  523.  
  524. C:
  525. int DFstat()
  526. DF*dfile/* pointer to an open HDF file  */
  527. struct DFdfinfo/* pointer to information about file */
  528.  
  529. Purpose:  To provide status information about an HDF file.
  530.  
  531. Return value:  0 on success; -1 on failure.
  532.  
  533. This routine currently does nothing but return the version number of the HDF library. It is intended for later expansion.
  534.  
  535.