home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / hdf / spec / hdf_03.txt < prev    next >
Text File  |  1994-06-01  |  181KB  |  4,809 lines

  1. NCSA HDF Specifications
  2. DRAFT
  3.  
  4. January 1993
  5.  
  6.  
  7. University of Illinois at Urbana--Champaign
  8.  
  9.  
  10.                           Introduction
  11.  
  12.  
  13. Overview
  14.  
  15. The Hierarchical Data Format (HDF) was designed to make the sharing
  16. of scientific data between different people, different projects,
  17. and different types of computers easy and self-describing. An
  18. extensible header, along with carefully crafted internal layers,
  19. provides a system that can grow along with the software that NCSA
  20. develops. This chapter provides a brief overview of HDF
  21. capabilities and design.
  22.  
  23.  
  24. Why HDF?
  25.  
  26. A fundamental requirement of scientific data management is the
  27. ability to access as much information in as many ways and as
  28. quickly and easily as possible. To make this possible, there needs
  29. to be a data storage and retrieval system that facilitates these
  30. capabilities. Specific needs of such a system include the
  31. following.
  32.  
  33. *  Support for scientific data and metadata. Scientific data is
  34.    characterized by a variety of different data types and
  35.    representations, data sets (including images) that can be
  36.    extremely large and complex, and the need to attach accompanying
  37.    attributes, parameters, notebooks, and other metadata.
  38.  
  39. *  Support for a range of hardware platforms. Data can originate
  40.    on one machine, only to be used later on many different
  41.    machines. Scientists must be able to access data and metadata
  42.    on as many hardware platforms as possible
  43.  
  44. *  Support for a range of software tools. Scientists need a variety
  45.    of software tools and utilities for easily searching, analyzing,
  46.    archiving, and transporting the data and metadata. These tools
  47.    range from a library of routines for reading and writing data
  48.    and metadata to small utilities that simply display an image on
  49.    a console, to full-blown database retrieval systems that provide
  50.    multiple views of thousands of sets of data and metadata.
  51.  
  52. *  Rapid data transfer. Both the size and the dispersion of
  53.    scientific data sets require that mechanisms must exist to get
  54.    the data from place to place rapidly.
  55.  
  56. *  Extendibility. As new types of information are generated and new
  57.    kinds of science are done, a means must be provided to support
  58.    them.
  59.  
  60.  
  61. What is HDF?
  62.  
  63. The structure of HDF. HDF is a self-describing extensible file
  64. format based on the use of tagged objects that have standard
  65. meanings. The idea is to store both a known format description and
  66. the data in the same file. HDF tags describe the format of the data
  67. in the sense that each tag is assigned a specific meaning--one tag
  68. is assigned to "Color Palette," another is assigned to "Raster
  69. Image," and so on (see Figure 1). A program that has been written
  70. to understand a certain list of tag types can scan the file for
  71. those tag types and process the data. This program also can ignore
  72. any data that is beyond its scope.
  73.  
  74. The set of available data objects encompasses both primary and
  75. secondary data (metadata). Most HDF objects are machine- and
  76. medium-independent, physical representations of data and metadata.
  77.  
  78. HDF Tags. HDF is designed with the assumption that we cannot know
  79. a priori what types of data objects will be needed in the future,
  80. nor can we know how scientists will want to view their data. As new
  81. science is done, new types of data objects are needed, and new tags
  82. must be created. In order to avoid unnecessary proliferation of
  83. tags, and to insure that all tags are available to potential users
  84. who need to share data, a portable public domain library is
  85. available that interprets all public tags. The library contains
  86. user interfaces designed to provide views of the data that are most
  87. natural for users. As we learn more about the way scientists need
  88. to view their data, we can add user interfaces that reflect data
  89. models consistent with those views.
  90.  
  91. Types of data and structures. HDF currently supports the most
  92. common types of data and metadata that scientists use, including
  93. multidimensional gridded data, 2d and 3d raster images, polygonal
  94. mesh data, multivariate datasets, sparse matrices, finite-element
  95. data, splines, non-Cartesian coordinate data, and text. In the
  96. future there will almost certainly be a need to incorporate new
  97. types of data, such as voice and video, some of which might
  98. actually be stored on other media than the central file itself. In
  99. this sense, it may be desirable to employ the concept of a "virtual
  100. file", which functions like a file, but doesn't fit our normal
  101. notion of a file as a monolithic sequence of bits stored entirely
  102. on a disk or tape somewhere.
  103.  
  104. HDF also makes it possible for the user to include annotations,
  105. titles, and specific descriptions of the data in the file, so that
  106. files can be archived with human-readable information about the
  107. data and its origins.
  108.  
  109. One collection of HDF tags supports a hierarchical grouping
  110. structure called vset that allows scientists to organize data
  111. objects within HDF files to fit their views of how the objects go
  112. together, much as a person in an office or laboratory organizes
  113. information in folders, drawers, journal boxes, and on their
  114. desktops.
  115.  
  116. *** INSERT FIGURE HERE ***
  117.  
  118. Backward and forward compatibility. An important goal of HDF is to
  119. maximize backward and forward compatibility among its interfaces.
  120. This is not always achievable, because changes sometimes have to
  121. be made to the way data is organized in order to enhance
  122. performance, to correct errors, or for other reasons. However,
  123. whenever possible, HDF files should not become out of date. For
  124. example, suppose a site falls far behind in the HDF standard, so
  125. its users can only work with the portions of the specification that
  126. are three years old. Users at this site might produce files with
  127. their old HDF software, then read them with newer software designed
  128. to work with more advanced data files. The newer software should
  129. still be able to read the old files.
  130.  
  131. Conversely, if the site receives files that contain objects that
  132. its HDF software does not understand, it should still be able to
  133. list the types of data in the file, and it should still be able to
  134. access all of the older types of data objects that it understands,
  135. despite the fact that the older types of data objects are mixed in
  136. with new kinds of data. In addition, if the more advanced site uses
  137. the text annotation facilities of HDF effectively, the files will
  138. arrive Appendix A, "NCSA HDF Tags," presents a list of brief
  139. descriptions of the tags assigned at NCSA for general use.
  140.  
  141. Appendix B, "Header Files," includes the general header files used
  142. in compiling all HDF libraries.
  143.  
  144.  
  145. Form of Presentation
  146.  
  147. The material in this manual is presented in text or Presentation
  148. screen displays.
  149.  
  150.  
  151. Text
  152.  
  153. In explaining various features and commands, this manual often
  154. presents a word within a paragraph in italics to indicate that the
  155. word is defined within the paragraph.
  156.  
  157. Portions of this manual refer to other portions of the manual where
  158. the other portions explain related topics. These cross references
  159. usually mention the title of sections or chapters enclosed in
  160. quotation marks, such as, See Chapter 1, "The Basic Structure of
  161. HDF Files."
  162.  
  163.  
  164. Screen Displays.
  165.  
  166. Screen displays in this manual are presented in Courier type.
  167.  
  168. long process of redesigning the lower layers of HDF began. As of
  169. this writing, in Summer 1982, we are about to release the first
  170. version of HDF that incorporates the new lower layers of HDF.
  171.  
  172.  
  173. Use of This Manual
  174.  
  175. This manual is designed for software developers who are designing
  176. applications or routines for use with HDF files and for users who
  177. need detailed information about HDF. Users who are interested in
  178. using HDF to store or manipulate their data do not normally need
  179. the kind of detail presented in this manual. They should instead
  180. consult a user manual, such as "HDF Calling Interfaces and
  181. Utilities," "HDF Vset", or perhaps a manual having to do with
  182. software that uses HDF.
  183.  
  184.  
  185. Manual Contents
  186.  
  187. The manual is organized into the following chapters:
  188.  
  189. Chapter 1, "The Basic Structure of HDF Files," introduces and
  190. describes the components and organization of Hierarchical Data
  191. Format files.
  192.  
  193. Chapter 2, "HDF Software Overview," describes the organization of
  194. the software layers that make up the basic HDF library.
  195.  
  196. Chapter 3, "The NCSA HDF General Purpose Interface," describes the
  197. HDF modules that make up the general purpose HDF routines,
  198. sometimes referred to as the lower layer of HDF.
  199.  
  200. Chapter 4, "Sets and Groups," explains the role of sets and groups
  201. in an HDF file. It contains descriptions of raster image sets,
  202. scientific datasets, and Vsets. Vsets are covered in more detail
  203. in another chapter.
  204.  
  205. Chapter 5, "Annotations," explains how annotations are currently
  206. organized in HDF files.
  207.  
  208. Chapter 6, "Number Conversion," describes the HDF module that is
  209. used for number conversion.
  210.  
  211. Chapter 7, "Vsets," describes the structure and functioning of the
  212. Vset module.
  213.  
  214. Chapter 8, "Portability," describes techniques and conventions used
  215. in the HDF code to achieve portability.
  216.  
  217. Chapter 9, "HDF Conventions," presents guidelines regarding the use
  218. of HDF that are not discussed elsewhere.
  219.  
  220.  
  221.                         Table of Contents
  222.  
  223.  
  224. Introduction
  225.      Overview vii
  226.  
  227.      Why HDF vii
  228.  
  229.      What Is HDF viii
  230.  
  231.      Some History x
  232.  
  233.      Use of This Manual x
  234.  
  235. Chapter 1 The Basic Structure of HDF Files
  236.  
  237.      Chapter Overview 1.1
  238.  
  239.      File Header 1.1
  240.  
  241.      Data Object 1.1
  242.  
  243.      Physical Organization of HDF Files 1.4
  244.  
  245.      Sample HDF File 1.5
  246.  
  247. Chapter 2 Software Overview
  248.  
  249.      Chapter Overview 2.1
  250.  
  251.      Software Layers 2.1
  252.  
  253.      Organization of HDF Software 2.2
  254.  
  255.      Some HDF Conventions 2.5
  256.  
  257. Chapter 3 The NCSA HDF General Purpose Interface
  258.  
  259.      Chapter Overview 3.1
  260.  
  261.      Introduction 3.1
  262.  
  263.      Overview of the interface 3.2
  264.  
  265.      Function Specifications 3.6
  266.  
  267. Chapter 4 Sets and Groups
  268.  
  269.      Chapter Overview 4.1
  270.  
  271.      Sets 4.1
  272.  
  273.      Groups 4.2
  274.  
  275.      Raster Image Sets 4.4
  276.  
  277.      Scientific Datasets 4.6
  278.  
  279.      Vsets and Vdatas 4.12
  280.  
  281.      Appendix: The Raster-8 Set 4.13
  282.  
  283. Chapter 5 Annotations
  284.  
  285.      Chapter Overview 5.1
  286.  
  287.      Types of Annotations 5.1
  288.  
  289.      File Annotations 5.1
  290.  
  291.      Object Annotations 5.1
  292.  
  293.      Getting Reference Numbers for Object
  294.  
  295.      Annotations 5.2
  296.  
  297. Chapter 6 Tag Specifications
  298.  
  299.      Overview 6.1
  300.  
  301.      The HDF Tag Space 6.1
  302.  
  303.      Physical Storage Methods 6.1
  304.  
  305.      Specifications for Supported Tags 6.4
  306.  
  307. Chapter 7 Making HDF Portable
  308.  
  309.      Chapter Overview 7.1
  310.  
  311.      The HDF Environment 7.1
  312.  
  313.      Organization of Source Files 7.2
  314.  
  315.      Passing Strings Between.FORTRAN and C 7.5
  316.  
  317.      Function Return Values between FORTRAN and C 7.7
  318.  
  319.      Differences in Acceptable Routine Names 7.8
  320.  
  321.      ANSI C vs. Old C 7.11
  322.  
  323.      Type Differences 7.12
  324.  
  325.      Access to Library Functions 7.15
  326.  
  327.  
  328. Figures and Tables
  329.  
  330. Figure 0.1   Raster Image Sets in an HDF File viii
  331. Figure 1.1   Three Data Objects 1.1
  332. Figure 1.2   A Data Descriptor 1.2
  333. Figure 1.3   Model of a Data Descriptor Block 1.3
  334. Figure 1.4   Sample Data Descriptor Block 1.4
  335. Figure 1.5   Physical Representation of Data Objects 1.5
  336. Figure 2.1   HDF software layers 2.1
  337. Figure 4.1   Physical organization of Sample RIG Groupings 4.3
  338. Figure 5.1   Three SDS Tags with Their Ref Numbers 5.1
  339. Figure 5.2   Displayed Example of SDS, Ref #, and Annotation 5.2
  340. Figure 6.1   Description Record for a Linked Block Element 6.2
  341. Figure 6.2   A Linked Block Table 6.3
  342. Figure 6.3   A Data Block 6.3
  343. Figure 6.4   Description Record for an External Element 6.4
  344. Figure 7.1   Illustration of the sequence of actions Involved when
  345.                a FORTRAN call includes a string as a parameter 7.7
  346.  
  347. Table 1.1    Parts of a Data Descriptor 1.2
  348. Table 1.2    Summary of the Relationships among Parts of an HDF
  349.                File 1.4
  350. Table 1.3    Sample Data Objects in an HDF File 1.5
  351. Table 2.1    HDF 3.2 source code modules 2.5
  352. Table 4.1    Tags for Raster Image Sets 4.5
  353. Table 4.2    Additional tags for Raster Image Sets 4.5
  354. Table 4.3    Required tags for SDG 4.8
  355. Table 4.4    Optional Tags for SDG 4.
  356. Table 4.5    Required tags for NDG 4.9
  357. Table 4.6    Optional Tags for NDG 4.10
  358. Table 4.7    Required Tags for NDG structure that is compatible
  359.                with SDG structure 4.10
  360. Table 4.8    Tags for Raster-8 Sets 4.14
  361. Table 5.1    HDF Annotation tags 5.1
  362. Table 6.1    Number Type Values 6.7
  363. Table 6.2    Possible Machine Types 6.8
  364. Table 6.3    Possible Tag Types in an RIG 6.12
  365. Table 6.4    Color Format String Values 6.16
  366. Table 6.5    Possible Tag Types in an NDG 6.21
  367. Table 6.6    Possible calibrated data types 6.28
  368. Table 6.7    Possible Tag Types in an SDG 6.34
  369. Table 6.9    Scientific Data Dimension Record Fields 6.12
  370.  
  371.  
  372. Chapter 1 The Basic Structure of HDF Files
  373.  
  374. Chapter Overview
  375. File Header
  376. Data Object
  377.      Data Descriptor
  378.      DD Blocks
  379.      Data Element
  380. Naming and Assigning Tags
  381. Physical Organization of HDF Files
  382. Sample HDF File
  383.  
  384.  
  385. Chapter Overview
  386.  
  387. This chapter introduces and describes the components and
  388. organization of Hierarchical Data Format (HDF) files.
  389.  
  390.  
  391. File Header
  392.  
  393. The first component of an HDF file is the file header (FH), which
  394. takes up the first four bytes in an HDF file. The file header is
  395. a signature that indicates that the file is an HDF file.
  396. Specifically, it is the 32-bit magic number with the 32-bit
  397. hexadecimal value 0e031301.
  398.  
  399. NOTE: HDF assumes big-endian order in reading and writing files.
  400. On some machines the order of bytes in the file header might be
  401. swapped when the header is written to an HDF file, causing these
  402. characters to be written in little endian. To maintain portability
  403. of HDF files when developing software for such machines, you should
  404. counteract this byte-swapping by making sure the characters are
  405. read and written in the exact order shown.
  406.  
  407.  
  408. Data Object
  409.  
  410. The basic building block in an HDF file is the data object, which
  411. contains both data and information about the data. A data object
  412. has two parts: a 12-byte data descriptor (DD) and a data element.
  413. Figure 1.1 shows three examples of data objects.
  414.  
  415. As the names imply, the data descriptor gives information about the
  416. data, and the data element it the data itself. In other words, all
  417. data in an HDF file has attached to it information about itself.
  418. In this sense, HDF files are examples of self-describing files.
  419.  
  420. ED. NOTE:  Figures are not available in this plain text version
  421. of the specification.
  422.  
  423. Figure 1.1 Three Data Objects
  424.  
  425.  
  426.  
  427. Data Descriptor (DD)
  428.  
  429. A data descriptor (DD) has four fields: a 16-bit tag, a 16-bit
  430. reference number, a 32-bit data offset, and  32-bit data length.
  431. These parts of a DD are depicted in Figure 1.2 and are briefly
  432. described in Table 1.1. Explanations of each part appear in the
  433. paragraphs following Table 1.1.
  434.  
  435. *** INSERT FIGURE HERE ***
  436.  
  437. Table 1.1  Parts of a Data Descriptor
  438.  
  439. Part                Description
  440.  
  441. tag                 designates the type of data in a data element
  442. reference number    uniquely distinguishes corresponding data
  443.                     element from others with the same tag
  444. data identifier     tag/ref; uniquely identifies data element
  445. offset              byte offset of corresponding data element
  446. length              length of data element
  447.  
  448.  
  449. Tag
  450.  
  451. A tag is the part of a data descriptor that tells what kind of data
  452. is contained in the corresponding data element. A tag is actually
  453. a 16-bit unsigned integer between 1 and 65535, but every tag is
  454. also usually given a name that programs can refer to instead of the
  455. number. If a DD has no corresponding data element, the value of its
  456. tag is DFTAG_NULL, indicating that no data is present.. A tag may
  457. never be zero.
  458.  
  459. Tags are assigned by NCSA as part of the specification of HDF. The
  460. following ranges are to be used to guide tag assignment:
  461.  
  462. 00001 - 32767  reserved for NCSA use
  463. 32768 - 64999  user-definable
  464. 65000 - 65535  reserved for expansion of the format
  465.  
  466. Appendix A contains full specifications for all currently supported
  467. NCSA HDF tags. Appendix B, "Assigned Tag Numbers," contains the
  468. current number assignments. See the section 'Some HDF Conventions"
  469. in the chapter "Software Overview" for more information on
  470. allocating tags.
  471.  
  472.  
  473. Reference Number
  474.  
  475. For each occurrence of a tag in an HDF file, a unique reference
  476. number is stored with the tag in the data descriptor. Reference
  477. numbers are 16-bit unsigned integers.
  478.  
  479. Reference numbers are not necessarily assigned consecutively, so
  480. you cannot assume that the actual value of a reference number has
  481. any meaning beyond providing a way of distinguishing among objects
  482. with the same tag.
  483.  
  484.  
  485. Data Identifier
  486.  
  487. The combination of a tag and its reference number uniquely
  488. identifies the corresponding data object in the file. For this
  489. reason, the tag/ref combination is sometimes referred to as a data
  490. identifier.
  491.  
  492.  
  493. Data Offset and Length
  494.  
  495. The data offset reflects the byte position of the corresponding
  496. data element from the start of the file. The length gives the
  497. number of bytes occupied by the data element. Offset and length are
  498. both 32-bit unsigned integers.
  499.  
  500.  
  501. DD Blocks
  502.  
  503. Data descriptors are stored physically in a linked list of blocks
  504. called data descriptor blocks, or DD blocks. The individual
  505. components of a data descriptor block are depicted in Figure 1.3.
  506. All of the DDs in a DD block are assumed to contain significant
  507. data unless they have a tag that is equal to DFTAG NULL (no data).
  508.  
  509. In addition to its DDs, each data descriptor block has a data
  510. descriptor header (DDH). The DDH has two fields--a block size field
  511. and a next block field. The block size field is a 16-bit unsigned
  512. integer that indicates the number of DDS in the following DD block.
  513. The next block field is a 32-bit unsigned integer giving the offset
  514. of the next DD block, if there is one. The last DDH in the list
  515. contains a 0 in its next block field.
  516.  
  517. *** INSERT FIGURE HERE ***
  518.  
  519.  
  520. Data Element
  521.  
  522. A data element is the raw data part of a data object. Its basic
  523. data type is determined by its tag, but other interpretive
  524. information may be required before it can be processed properly.
  525.  
  526. Each data element is stored as a set of contiguous bytes starting
  527. at the offset given in the corresponding DD (see Figure 1.4).(1)
  528.  
  529. *** INSERT FIGURE HERE ***
  530.  
  531.  
  532. Physical Organization of HDF Files
  533.  
  534. Physically, the file header, DD blocks, and data elements are
  535. organized as follows. The file header is followed by the first DD
  536. block, which is followed by data elements and, if necessary, more
  537. DD blocks. These relationships are summarized in Table 1.2.
  538.  
  539. There are no rules governing the distribution of DD blocks and data
  540. elements within a file, except that the first DD block must follow
  541. immediately after the file header. The pointers in the DD headers
  542. connect the DD blocks in a linked list, and the offsets in the
  543. individual DDs connect the DDS to the data elements. Beyond this
  544. basic structure there is no assumed order among the objects in an
  545. HDF file.
  546.  
  547. Table 1.2 Summary of the Relationships among Parts of an HDF File
  548.  
  549. Part           Constituents
  550. HDF File       FH, DD-block, data, DD-block, data, DD-block,
  551.                 data ... 
  552. F H            oxOe031301 (32 bit magic number)
  553. DD-block       DDH, DD, DD, DD ... 
  554. DDH            number-of-DDs (16 bits], offset-to-next-DD block (32
  555.                  bits)
  556. DD             tag (16 bits), ref [16 bits], offset (32
  557.                  bits),length (32 bits)
  558.  
  559.  
  560. (1) Some HDF software provides the capability of storing objects
  561. as a series of linked blocks or external elements, but this occurs
  562. at a higher level. At the lowest level each object with a tag/ref
  563. is stored contiguously.
  564.  
  565. Sample HDF File
  566.  
  567. Consider an HDF file that contains two 400-by-600 8-bit raster
  568. images. Typically, such a file might contain the objects described
  569. in Table 1.3.
  570.  
  571. Table 1.3  Sample Data Objects in an HDF File
  572.  
  573. Tag  Ref  Data
  574. FID   1   file identifier: user-assigned title for file
  575. FD    1   file descriptor: user-assigned block of text
  576.           describing overall file contents
  577. IP8   1   Image palette (768 bytes)
  578. ID8   1   x and y dimensions of the 2D arrays that contain
  579.           the raster images (4 bytes)
  580. RI8   1   first 2D array of raster image pixel data (x*y bytes)
  581. RI8   2   second 2D array of pixel data (also x*y bytes)
  582.  
  583. Assuming, for example, that the size of a DD block is 10 DDs, the
  584. physical organization of the contents of the file might be
  585. described as shown in Figure 1.5.
  586.  
  587. Figure 1.5 Physical Representation of Data Objects
  588.  
  589. Offset Contents
  590.  
  591.      0    FH
  592.      4    DDH       (10       0) 
  593.     10    DD        (FID      1         130       4)
  594.     22    DD        (FD       1         134       41)
  595.     34    DD        (IP8      1         175       768)
  596.     46    DD        (ID8      1         943       4)
  597.     58    DD        (RI8      1         947       240000)
  598.     70    DD        (RI8      2         240947    240000) 
  599.     82    DD        (empty)
  600.     94    DD        (empty)
  601.    106    DD        (empty)
  602.    118    DD        (empty)
  603.    130    "sw3"
  604.    134    "solar wind simulation: third try. 8/8/88"
  605.    175    <data for the image palette>
  606.    943    <data for the image dimensions>: 400, 600
  607.    947    <data for the first raster image>
  608. 240947    <data for the second raster image>
  609.  
  610. In this instance, the file contains two raster images. The two
  611. images have the same dimensions and are to be used with the same
  612. palette. So, the same data objects for the palette (IP8) and
  613. dimension record (ID8) can be used with both images.
  614.  
  615. Chapter 2      HDF Software Overview
  616.  
  617.                Chapter Overview
  618.                Introduction
  619.                Software Layers
  620.                Organization of HDF Software 
  621.                     Versions and Release Numbers
  622.                     ANSI C and Portability
  623.                     Modules and Interfaces
  624.                     Header Files
  625.                     The HDF Test Suite and Examples
  626.                Some HDF Conventions
  627.                     Naming and Assigning Tags
  628.                     Using Reference Numbers to Organize Data Objects
  629.                     Multiple References and File Compaction
  630.  
  631.  
  632. Chapter Overview
  633.  
  634. This chapter contains a description of how HDF software is
  635. organized. It also contains some guidelines on writing HDF
  636. software.
  637.  
  638.  
  639. HDF Software Layers
  640.  
  641. HDF-based software comes in four basic forms: an HDF interface
  642. library, user programs that store and retrieve data in HDF files,
  643. HDF command-line utilities, and HDF-based software tools.
  644.  
  645. The HDF interface library has two types of interfaces: (1) sets of
  646. general purpose routines that form the basis of all higher-level
  647. HDF development, and (2) application interfaces that support higher
  648. level views of data.
  649.  
  650. User programs access HDF files via calls to the HDF library. User
  651. programs are attached to the HDF library when they are compiled and
  652. linked.
  653.  
  654. The HDF command-line utilities are a group of programs that are
  655. distributed with the HDF library. The functionality of the
  656. command-line utilities ranges from general purpose, such as listing
  657. the contents of an HDF file, to special purpose, such as converting
  658. data between different HDF data types (e.g., raster images to
  659. scientific data sets). In general, the utilities perform data
  660. management tasks.
  661.  
  662. In contrast, HDF-based software tools usually perform data analysis
  663. tasks and have polished interactive user interfaces. They include
  664. the NCSA Visualization Tool Suite and commercial software packages
  665. that use HDF.
  666.  
  667. HDF software is implemented in layers, as illustrated in Figure
  668. 2.1. At the lowest level are the general purpose modules, which
  669. perform basic I/O. At the next level are interfaces that reflect
  670. commonly used objects such as B-bit raster images (RIS8) and
  671. multidimensional arrays (SDS). At the top layer are users'
  672. programs, utilities, and software tools such as the NCSA
  673. visualization software.
  674.  
  675. *** INSERT FIGURE HERE ***
  676.  
  677. The general purpose interfaces are described in detail in this
  678. document. Descriptions of the applications interfaces and
  679. command-line utilities can be found in the manual "HDF Calling
  680. Interfaces and Utilities." Each HDF-based software tool should have
  681. its own manual.
  682.  
  683. Since the NCSA user community writes programs primarily in C and
  684. Fortran, all of the HDF application interfaces developed at NCSA
  685. are callable from both C and Fortran programs. Since the general
  686. purpose interface is primarily for program development, not for
  687. applications, it provides C routines only.
  688.  
  689.  
  690. Organization of Software
  691.  
  692. Versions and Release Numbers
  693. Since HDF is under continual development, new releases are
  694. periodically made available. An HDF version number looks like
  695. "3.2r1" which means that it is major version 3, minor version 2,
  696. release 1. The three parts of a version number have different
  697. meanings:
  698.  
  699. * A new major version number implies that there is some fundamental
  700.   difference between this code and code with earlier major version
  701.   numbers. When a new major version is made available, HDF users
  702.   and developers are strongly encouraged to obtain the new source
  703.   code and documentation. There will likely be added functionality
  704.   in successive major versions.of the library and possibly some
  705.   deletion of obsolete code, so some user code may have to be
  706.   modified to use the new library.
  707.  
  708. * The meaning of a new minor version number is somewhat less well
  709.   defined. It essentially means that there is some appreciable
  710.   difference in the new code which was not deemed drastic enough
  711.   to warrant a new major version, but is more substantial than a
  712.   new release number would indicate.
  713.  
  714. * A new release number implies some bug fixes or other small
  715.   modifications have been made to the code. Using a new release of
  716.   the same version of the library will not usually require
  717.   modification of existing user code.
  718.  
  719.  
  720. ANSI C and Portability
  721.  
  722. In order to provide for easy porting of HDF to new platforms, all
  723. versions of the HDF source code from version 3.2 on will be written
  724. in ANSI standard C, with special provisions made for non-ANSI
  725. compilers. For more information about porting HDF and writing
  726. portable HDF-based code, refer to the chapter "Making HDF
  727. Portable."
  728.  
  729.  
  730. Modules and Interfaces
  731.  
  732. The HDF distribution contains many source files or modules which
  733. can be grouped into families according to their root name. For
  734. example, dfp.c, dfpf.c and dfpff.f all share the root name "dfp"
  735. and, therefore, all belong to the "dfp" family. In general, each
  736. family of source modules represents one HDF applications interface.
  737. Thus, the "dfp" family together represent the HDF Palette
  738. Interface. There are a few exceptions to this rule which will be
  739. discussed later in this section.
  740.  
  741. For each interface, there is necessarily one file that contains the
  742. C Code that provides the basic functionality of that interface. But
  743. some interfaces may have one or two additional code modules that
  744. provide Fortran callability for the interface. So there are three
  745. possible family sizes:
  746.  
  747. 1 file:
  748.   Modules of this sort are generally not calling interfaces
  749.   themselves, but rather provide useful support functions for
  750.   actual calling interfaces. Since they are not meant to be called
  751.   by any routine outside the HDF library itself, they do not need
  752.   to be callable from Fortran programs. An example of such a module
  753.   is hblocks.c.
  754.  
  755. 2 files:
  756.   Although there are currently no examples of this situation, it
  757.   is conceivable (and desirable) that some future interface may
  758.   need only one extra source module to provide Fortran
  759.   compatibility. If this were to happen, there would only be two
  760.   source modules for the interface. For instance, dfnew.c and
  761.   dfnewf.c would make up the "New Interface."
  762.  
  763. 3 files:
  764.   Most current implementations of Fortran-callable HDF interfaces
  765.   require the passing of character string arguments to some of
  766.   their functions. Due to differences in the way C and Fortran
  767.   represent strings, the passing of strings requires that there be
  768.   a small amount of special purpose Fortran code written for each
  769.   function that takes a string argument.
  770.  
  771.   For this reason, most Fortran-callable HDF interfaces consist of
  772.   three source modules:
  773.  
  774.      (1) the primary C module,
  775.      (2)a Fortran-callable C module, and 
  776.      (3) a Fortran module.
  777.  
  778.   For example, dfsd.c, dfsdf.c and dfsdff.f make up the Scientific
  779.   Data Set Interface. dfsd.c contains the basic functionality of
  780.   the interface, dfsdf.c provides the major part of Fortran
  781.   callability, and dfsdff.f contains the special purpose Fortran
  782.   code that allows the passing of character string arguments.
  783.  
  784.  
  785. Header Files
  786.  
  787. In addition to the source code modules discussed above, some
  788. interfaces also have C header files associated with them that are
  789. meant to be included by C applications programmers with the
  790. "#include" preprocessor directive. They contain some useful
  791. constants and data structures for interaction with the interface
  792. from C programs. The header files can be identified by the same
  793. name as the root name for the rest of the family with the ".h"
  794. extension added. For example, dfsd.h is the header file for the
  795. scientific Data Set Interface.
  796.  
  797. Of particular importance among the header files are hdf.h and
  798. hdfi.h. hdf.h is the C header file that must be included by any
  799. program that calls the HDF library. It contains all the symbolic
  800. constants and public data structures that are needed to use HDF.
  801. hdfi.h contains specific portability information about each
  802. platform on which HDF is supported. It is automatically included
  803. in programs when hdf.h is included, so programmers need not
  804. explicitly include it. For more information on hdfi.h and other
  805. portability issues, refer to the Chapter "Making HDF Portable.".
  806.  
  807. Table 2.1 shows all of the source code modules and header files
  808. grouped into families for HDF 3.2.
  809.  
  810. Table 2.1 HDF 3.2 source code modules
  811.  
  812. general   general   grouping  utilities Vsets     Old
  813. headers   purpose   (non-                         general
  814.                     Vset)                         purpose
  815. hdf.h     hfile.c   dfgroup.c dfutil.c   vg.c     dfstubs.c
  816. hdfi.h    hfilef.c  dfgroup.h dfutilf.c  vgf.c    dff.c
  817. hproto.h  hfileff.f           dfutilff.f vgff.f   dfff.f
  818. dfivms.h  hkit.c              dfutil.h   vfp.c    df.h
  819.           hblocks.c                      vgi.h    dfi.h
  820.           hextelt.c                      vio.c    dfstubs.h
  821.           herr.c                         vconv.c
  822.           herrf.c                        vparse.c
  823.           hfile.h                        vrw.c
  824.           herr.h                         vsfld.c
  825.                                          vg.h
  826.                                          vproto.h
  827.  
  828. 8/24 bit  general   palettes  scientifi annotatio special
  829. raster    raster              c data    ns        FORTRAN
  830.                               sets
  831. dfr8.c    dfgr.c    dfp.c     dfsd.c    dfan.c    constants.f
  832. dfr8f.c   dfgr.h    dfpf.c    dfsdf.c   dfanf.c   functions.f
  833. dfr8ff.f  dfcomp.c  dfpff.f   dfsdff.f  dfanff.f
  834. df24.c    dfimcomp.c          dfsd.h    dfan.h
  835. df24f.c   dfrig.h
  836. df24ff.f
  837.  
  838.  
  839. The HDF Test Suite and Examples
  840.  
  841. In addition to the source code for the HDF library, versions 3.2
  842. and higher will have an available suite of test programs There are
  843. at least two test programs for most interfaces: one for the C
  844. version and one for the Fortran-callable version. Some interfaces
  845. have more than two test programs to test special features of that
  846. interface and some have only one test program, since they only
  847. provide C-callability.
  848.  
  849. Every effort will be made to ensure that the test programs provide
  850. a thorough and accurate assessment of the health of the HDF
  851. library. Although it is hoped that the test suite will greatly
  852. improve the reliability of HDF code, it is almost inevitable that
  853. some parts of the code will be untested. Therefore, no guarantees
  854. can be made on the basis of test suite performance.
  855.  
  856. There is also a set of example programs to help users write HDF
  857. programs. They illustrate some of the common ways in which users
  858. program with HDF.
  859.  
  860.  
  861. Some HDF Conventions
  862.  
  863. The specification of HDF described in the previous chapter is not
  864. sufficient to guarantee its success. It is also important for users
  865. to adhere to certain conventions in using HDF. Guidelines in the
  866. use of HDF are implicit in many discussions in other sections of
  867. this document, and others are presented in the manual "HDF Calling
  868. Interfaces and Utilities." Guidelines not covered elsewhere are
  869. introduced in this section.
  870.  
  871.  
  872. Naming and Assigning Tags
  873.  
  874. Tags that are to be made available to a general population of HDF
  875. users should be assigned and controlled by NCSA. Tags of this type
  876. are given numbers in the range 1-32,767. If you have an application
  877. that fits this criterion, contact NCSA at the address listed on the
  878. README page at the beginning of this manual and specify the tags
  879. you would like. For each tag, your specifications should include
  880. a suggested name, information about the type and structure of the
  881. data that the tag will refer to, and information about how the tag
  882. will be used. Your specifications should be similar to those
  883. contained in Appendix A. NCSA will assign you a set of tags for
  884. your application and include your tag descriptions in its
  885. documentation.
  886.  
  887. Tags in the range 32,768-64,999 are user-definable. That is, you
  888. can assign them for any private application. Of course, if you use
  889. tags in this range you need to be aware that they may conflict with
  890. other people's private tags.
  891.  
  892.  
  893. Using Reference Numbers to Organize Data Objects
  894.  
  895. The HDF library itself uses reference numbers solely for the
  896. purpose of distinguishing between different objects with the same
  897. tag. While application programmers may find it convenient to impart
  898. some meaning to reference numbers, they should be forewarned that
  899. the HDF library will be ignorant of any such meaning. In other
  900. words, any meaning attached to reference numbers exists only at the
  901. application program or software tool level.
  902.  
  903. Some users have used reference numbers to indicate how objects
  904. should be grouped by considering all objects with the same
  905. reference number to be part of the same group. This practice is not
  906. recommended. Instead, if object grouping is desired it is
  907. recommended that you use either the simple grouping procedures used
  908. by the SDS, RIS8, and RIS24 applications (supported by the routines
  909. in dfgroup.c), or the more general (and more complex) Vset
  910. structures.
  911.  
  912. Another possible use of reference numbers is for keyed access to
  913. HDF objects. An HDF data identifier (tag/ref) provides an unique
  914. identifier for any HDF object within a file, and hence could be
  915. used as a primary key for that object. One could keep a table of
  916. data identifiers as a way of providing random access to HDF
  917. objects.
  918.  
  919. Reference numbers might also be used to impose an ordering on HDF
  920. objects. Once again, because the assignment scheme for reference
  921. numbers in HDF files does not guarantee any order, caution is
  922. advised in this uses of reference numbers.
  923.  
  924.  
  925. Multiple References
  926.  
  927. Multiple references to a single data element are quite common in
  928. HDF. The general purpose routine Hdupdd generates a new reference
  929. to data that is already pointed to by another DD. If Hdupdd is used
  930. several times, there could be several DDs that point to the same
  931. data element.
  932.  
  933. It is important to note that when a multiply-referenced data
  934. element is deleted or moved, the various DDs that previously
  935. pointed to the data element are not automatically deleted or
  936. adjusted to point to the data element in its new location.
  937. Consequently, each DD to be deleted or moved should be checked for
  938. multiple references and handled as the programmer sees fit.
  939.  
  940.  
  941. Chapter 3      The NCSA HDF General Purpose Interface
  942.  
  943.                Chapter Overview
  944.                Introduction
  945.                Overview of the Interface
  946.                Function Specifications
  947.                     Opening and Closing Files
  948.                     Finding Tags, Refs, and Element Lengths
  949.                     Reading and Writing Entire Data Elements
  950.                     Reading and Writing Part of a Data Element
  951.                     Manipulating Data Descriptors (DDs)
  952.                     Creating Special Data Elements
  953.                     Development Routines
  954.                     Error Reporting
  955.  
  956.  
  957. Chapter Overview
  958.  
  959. This chapter contains a detailed description of the routines that
  960. make up the general purpose HDF interface.
  961.  
  962. Introduction
  963.  
  964. NCSA supports interfaces for HDF users--both high level interfaces
  965. to support certain application areas, such as image processing, and
  966. low level general purpose interfaces for performing basic
  967. operations on HDF files. These interfaces are written in C only but
  968. most functions are typically accessible from Fortran.
  969.  
  970. The routines in the general purpose interface enable you to build
  971. and manipulate HDF objects of any type, including those of your own
  972. invention. All HDF applications developed at NCSA use these
  973. routines as their basic building blocks.
  974.  
  975. The routines described in this chapter represent a second set of
  976. general purpose routines. All HDF applications prior to HDF 3.2
  977. (released in June 1992) used an earlier set of general purpose
  978. routines. These low level general purpose routines have been
  979. changed to allow for better functionality. Old routines will still
  980. be emulated but at a cost of reduced functionality. Users are
  981. strongly advised to use the new interface.
  982.  
  983. The new lower layer, first used with HDF Version 3.2, incorporates
  984. the following improvements over its predecessor:
  985.  
  986. * More consistent data and function types.
  987.  
  988. * An error handling module that supports more meaningful and
  989.   extensive reporting of errors.
  990.  
  991. * Simplification of key lower level functions.
  992.  
  993. * Simplified techniques for facilitating portability.
  994.  
  995. * Support for alternate forms of physical storage, such as linked
  996.   blocks storage, and storage of the data portion of an object in
  997.   an external file.
  998.  
  999. * A version tag indicating which version of the HDF library last
  1000.   changed an HDF file.
  1001.  
  1002. * Support for simultaneous access to multiple files.
  1003.  
  1004. * Support for simultaneous access to multiple objects within a
  1005.   single file.
  1006.  
  1007. The previous lower layer is called the "DF layer", because all
  1008. routines began with the letters "DF", as in "DFopen" and "DFclose."
  1009. The new layer is called the "H layer" because all routines begin
  1010. with the letter "H" (Hopen, Hclose, Hwrite, etc.). The source
  1011. modules that implement these changes can be found in files that
  1012. begin with the letter "h".
  1013.  
  1014. Also, the number of basic source modules has changed, and now
  1015. includes:
  1016.  
  1017. hfile.c          basic I/O
  1018. herr.c           error-handling
  1019. hkit.c           general purpose routines
  1020. hblocks.c        to support linked block physical storage
  1021. hextelt.c        to support external storage of HDF data
  1022.  
  1023. Overview of the interface
  1024.  
  1025. Following is a listing of the public functions that can be found
  1026. in the general purpose interface. This section provides
  1027. specifications and descriptions of these routines.
  1028.  
  1029. Opening and Closing HDF Files
  1030.  
  1031. These calls are used to open and close HDF files.
  1032.  
  1033. Hopen            Provides an access path to an HDF file. It also
  1034.                  reads into memory all of the DD blocks in the
  1035.                  file.
  1036.  
  1037. Hclose           Closes the access path to a file.
  1038.  
  1039. Locating Elements for Access and Getting Information
  1040.  
  1041. These routines make it possible to locate elements or find out
  1042. other information. Except for Hendaccess, they initialize the
  1043. element that they locate and return an access id that is used in
  1044. later references to the data element. Calls to them can include
  1045. wild cards so that one can search for unknown tags and refs.
  1046.  
  1047. Hstartread       Locates an existing data element with matching
  1048.                  tag/ref and returns an access id for reading it.
  1049.  
  1050. Hnextread        Continues the search with the same access id.
  1051.  
  1052. Hstartwrite      Allows writing to the object with the supplied
  1053.                  tag/ref. If the object exists, the object will be
  1054.                  modified, otherwise it is created.
  1055.  
  1056. Hendaccess       Disposes of access id for tag/ref.
  1057.  
  1058. Hinquire         Returns access information about a data element.
  1059.  
  1060. Hishdf           Determines whether a file is an HDF file.
  1061.  
  1062. Hnumber          Returns the number of occurrences of a specified
  1063.                  data identifier (tag/ref) in a file.
  1064.  
  1065. Hgetlibversion   Returns version information for the current HDF
  1066.                  library
  1067.  
  1068. Hgetfileversion  Returns version information for an HDF file
  1069.  
  1070.  
  1071. Reading and Writing Entire Data Elements
  1072.  
  1073. There are two sets of routines for reading and writing data
  1074. elements. The set of routines described here is used to store and
  1075. retrieve entire data elements. A second set of routines, described
  1076. in the next section, may be used if you wish to access only part
  1077. of a data element at a time.
  1078.  
  1079. Hputelement      Adds or replaces elements in a file.
  1080.  
  1081. Hgetelement      Obtains the data referred to by the tag/ref
  1082.                  combination that is passed to it.
  1083.  
  1084.  
  1085. Reading and Writing Part of a Data Element
  1086.  
  1087. The second set of routines for reading and writing data elements
  1088. makes it possible to read or write all or part of a data element,
  1089. in contrast to the routines described above which can only read or
  1090. write an entire element. One of the access routines Hstartread or
  1091. Hstartwrite must be called before calling these routines.
  1092.  
  1093. Hwrite           Appends data to a data element. It starts at the
  1094.                  last position left by a Hwrite or Hseek command,
  1095.                  writes up to a specified number of bytes, then
  1096.                  leaves the access pointer at the end of the data
  1097.                  written.
  1098.  
  1099. Hread            Reads a portion of a data element. It starts at
  1100.                  the last position left by a Hread or Hseek command
  1101.                  and reads any data that remains in the element up
  1102.                  to a specified number of bytes.
  1103.  
  1104. Hseek            Sets the access pointer to an offset within a data
  1105.                  element. The next time Hread or Hwrite is called,
  1106.                  the access occurs from the new position. The
  1107.                  location to seek to can be specified as an offset
  1108.                  from the current location or from the start of the
  1109.                  element.
  1110.  
  1111.  
  1112. Manipulating Data Descriptors (DDs)
  1113.  
  1114. These routines perform operations on DDs without doing anything
  1115. with the data to which the DDs refer.
  1116.  
  1117. Hdupdd           Is used to generate new references to data that
  1118.                  is already referenced from somewhere else.
  1119.  
  1120. Hdeldd           Deletes a tag/ref from the list of DDs.
  1121.  
  1122. Hnewref          Returns the next available reference number for
  1123.                  the HDF file.
  1124.  
  1125.  
  1126. Creating Special Data Elements
  1127.  
  1128. HDF 3.2 introduces two alternate methods of physical storage for
  1129. HDF objects. Previously, all of the objects in an HDF "file" had
  1130. to be in the same file and any given object had to be contiguous.
  1131. This last requirement caused many problems, especially with regard
  1132. to appending to existing objects. Objects needed to be deleted and
  1133. rewritten to the end of the file in order to append to them.
  1134.  
  1135. The two new storage methods are "linked blocks" and "external
  1136. elements". Linked blocks allow elements in a single HDF file to be
  1137. non-contiguous. External elements allow a single HDF object to be
  1138. stored in an external file. It is not currently possible to have
  1139. a single object (such as a very large data set) stored in multiple
  1140. files. Nor is it possible to have multiple objects stored in an
  1141. "external" file.
  1142.  
  1143. Special data elements can be accessed with the same routines as for
  1144. normal data elements once they are created. These routines create
  1145. special data elements.
  1146.  
  1147. HLcreate         Creates a new linked block special data element.
  1148.  
  1149. HXcreate         Creates a new external file special data element.
  1150.  
  1151. Both of these routines have two modes of operation. For example,
  1152. calling HLcreate with a tag and ref which do not exist in a file
  1153. will create i new element with the given tag and ref that will be
  1154. stored as linked blocks. On the other hand, if the tag/ref pair
  1155. already existed in the file, the referenced object is "promoted"
  1156. to being stored as linked blocks. All data which had been stored
  1157. in the object before the promotion is retained. HXcreate behaves
  1158. similarly.
  1159.  
  1160. Development Routines
  1161.  
  1162. The HDF library provides a number of "developer" level routines
  1163. that are meant to simplify the task of writing HDF applications.
  1164. most of these routines mirror basic C library functions which are,
  1165. unfortunately, not always completely portable in their library
  1166. form.
  1167.  
  1168. HDgettagname     Return a pointer to a text string describing a
  1169.                  given tag.
  1170.  
  1171. HDgetapace       Allocate space.
  1172.  
  1173. HDfreespace      Free space.
  1174.  
  1175. HDstrncpy        Copy a string from one location to another up to
  1176.                  a given number of characters.
  1177.  
  1178.  
  1179. Error Reporting
  1180.  
  1181. The HDF library now provides a much more robust error reporting
  1182. scheme. Previously, only a single error value could be returned to
  1183. the user. There is now the notion of an error stack. This allows
  1184. for more of the context to be known when trying to decipher a
  1185. problem.
  1186.  
  1187. HEprint          Print out all of the errors on the error stack to
  1188.                  a specified nfile.
  1189.  
  1190. HEclear          Clear the error stack.
  1191.  
  1192. HERROR           Macro to report an error. This will push the error
  1193.                  type, file name, line number and name of the
  1194.                  function reporting the error.
  1195.  
  1196. HEreport         Add a text string to the description of the most
  1197.                  recently reported error. Only a single text string
  1198.                  may be supplied per error.
  1199.  
  1200. The only problem with the error module is that standard C does not
  1201. have any way for the code inside a function to know the name of the
  1202. function. Therefore, in order to use the macro HERROR to report
  1203. errors, there must exist a variable FUNC which points to a string
  1204. containing the name of the reporting function.
  1205.  
  1206. Other
  1207.  
  1208. Hsync            Synchronize stored version of HDF file with image
  1209.                  in memory.
  1210.  
  1211.  
  1212. Function Specifications
  1213.  
  1214. Opening and Closing files
  1215.  
  1216. Hopen
  1217.  
  1218. int32 Hopen(char *path, int access, int16 ndds)
  1219.  
  1220.      path   IN:  Name of file to be opened
  1221.      access IN:  DFACC_READ, DFACC_WRITE, DFACC_CREATE or
  1222.                  anybitwise-or of the above
  1223.      ndds   OUT: Number of dds in a block if this file needs to be
  1224.                  created
  1225.  
  1226.      Purpose: Provides an access path to an HDF file. It also reads
  1227.      into primary memory all of the DD blocks in the file.
  1228.  
  1229.      Returns: On success returns file id, on failure returns FAIL.
  1230.  
  1231.      Description: Opens an HDF file.
  1232.  
  1233.      Interpretations of access:
  1234.            HDF provides several constants for use as access
  1235.            privilege codes. Below is a list of these codes and
  1236.            their meanings. It is important to note that these
  1237.            constants are NOT bitflags and should NOT be or'd
  1238.            together to combine access modes. Doing so may cause odd
  1239.            behavior and, in some cases, loss of data.
  1240.  
  1241.            Recommended:
  1242.              DFACC_READ:    Open for read only. If file does not
  1243.                             exist, error.
  1244.              DFACC_RDWR:    Open for read/write. If file does not
  1245.                             exist, create it.
  1246.              DFACC_CREATE:  Force creation. If file exists, delete
  1247.                             it, then open a new file for
  1248.                             read/write. (in the spirit of UNIX
  1249.                             "clobber")
  1250.  
  1251.            Others:
  1252.              DFACC_ALL:     Same as DFACC_RDWR.
  1253.              DFACC_WRITE:   Same as DFACC_RDWR.
  1254.  
  1255. On successful exit,
  1256. * File_rec members are filled in.
  1257. * File is opened with the relevant permission.
  1258. * Information about dd's are set up in memory.
  1259.  
  1260. For a new file, in addition,
  1261. * The file headers and initial information are set up.
  1262.  
  1263. Hclose
  1264.  
  1265. intn Hclose(int32 id)
  1266.  
  1267.      id            IN: the file id of the file to be closed
  1268.  
  1269.      Purpose:      Closes the access path to the file.
  1270.  
  1271.      Returns:      SUCCEED (0) if successful and FAIL (-1) if
  1272.                    failed.
  1273.  
  1274.      Description:  Id is first validated. If valid, the function
  1275.                    closes the acces path to the file.
  1276.  
  1277.                    If there are still access elements attached to
  1278.                    the file, the e DFE_OPENAID is returned and the
  1279.                    file is not closed.
  1280.  
  1281.                    This is a fairly common error when developing
  1282.                    new interfaces. the discussion of Hendaccess
  1283.                    below for hints on how to debug problem.
  1284.  
  1285. Locating Elements for Access and Getting Information
  1286.  
  1287. Hstartread
  1288.  
  1289. int32 Hstartread(int fileid, int tag, int ref)
  1290.  
  1291.      fileid        IN: id of file to attach access element to
  1292.      tag           IN: tag to search for
  1293.      ref           IN: ref to search for
  1294.  
  1295.      Purpose:      Locate an existing data element with matching
  1296.                    tag/ref and return a descriptor for reading it.
  1297.  
  1298.      Returns:      On success returns id of access element if
  1299.                    successful, otherwise FAIL (-1).
  1300.  
  1301.      Description:  Searches the DD's for a particular tag/ref
  1302.                    combination. Wildcards can be used for tag or
  1303.                    ref (DFTAG_WILDCARD, DFREF_WILDCARD) and they
  1304.                    match any values. Searching on wildcards begins
  1305.                    from the beginning of the DD list. If the search
  1306.                    is successful, the access element is positioned
  1307.                    to the start of that tag/ref, otherwise it is
  1308.                    an error. An access element is created and
  1309.                    attached to the file.
  1310.  
  1311. Hnextread
  1312.  
  1313. intn Hnextread(int32 access_id, int16 tag, int16 ref, int origin)
  1314.  
  1315.      access_id     IN: Id of a READ access elt
  1316.      tag           IN: the tag to search for
  1317.      ref           IN: ref to search for
  1318.      origin        IN: from where to start searching
  1319.  
  1320.      Purpose:      Locate and position a read access id on next
  1321.                    occurrence of tag/ref.
  1322.  
  1323.      Returns:      SUCCEED (0) if successful and FAIL (-1)
  1324.                    otherwise.
  1325.  
  1326.      Description:  Searches for the "next" DD that fits the
  1327.                    tag/ref. Wildcards apply. If origin is DF_START,
  1328.                    search from start of DD list, if origin is
  1329.                    DF_CURRENT, search from current position.
  1330.                    Searching from the end of the file via DF_END
  1331.                    is not yet implemented.
  1332.  
  1333.                    If the search is successful, then the access
  1334.                    element is positioned at the start of that
  1335.                    tag/ref, otherwise, the access_id is not
  1336.                    modified.
  1337.  
  1338. Hstartwrite
  1339.  
  1340. int32 Hstartwrite(int fileid, int tag, int ref, long len)
  1341.  
  1342.      fileid        IN: Id of file to write to
  1343.      tag           IN: tag to write to
  1344.      ref           IN: ref to write to
  1345.      length        IN: the length of the data element
  1346.  
  1347.      Purpose:      Creates or replace data element with matching
  1348.                    tag/ref.
  1349.  
  1350.      Returns:      Id of access element if successful and FAIL
  1351.                    otherwise.
  1352.  
  1353.      Description:  Set up an access element to write out a data
  1354.                    element. DD list of the file is searched first.
  1355.                    If the tag/ref is four the data element is NOT
  1356.                    replaced; rather, it is then possible modify the
  1357.                    existing data. If an object with the
  1358.                    corresponding and ref does not exist, a new one
  1359.                    is created.
  1360.  
  1361. Hendaccess
  1362.  
  1363. int32 Hendaccess(int access_id)
  1364.  
  1365.      access-id     IN: id of access element to dispose of
  1366.  
  1367.      Purpose:      Disposes of descriptor for tag/ref.
  1368.  
  1369.      Returns:      returns SUCCEED (0) if successful, FAIL (-1)
  1370.                    otherwise.
  1371.  
  1372.      Description:  Used to dispose of an access element. There is
  1373.                    only a finite number of access elements allowed
  1374.                    to be active at a time. Therefore, it is very
  1375.                    important to call Hendaccess whenever you are
  1376.                    done using an element.
  1377.  
  1378.                    When developing new interfaces, we have found
  1379.                    that a fairly common mistake is to not call
  1380.                    Hendaccess for all of the elements accessed.
  1381.                    When this happens, Hclose will return FAIL, and
  1382.                    the dump of the error stack (see HEprint, below)
  1383.                    will tell how many access elements are still
  1384.                    active.
  1385.  
  1386.                    This is a rather difficult problem to debug, as
  1387.                    the low level the HDF library have really no
  1388.                    idea who and where opened an access element and
  1389.                    forgot to release it. It's tedious, but the most
  1390.                    effective means we have found to debug this
  1391.                    problem is to annotate the locations where the
  1392.                    `attached' count of a file record is changed
  1393.                    (there are a couple of places in hfile.c ar few
  1394.                    in hblocks.c and hextelt.c).
  1395.  
  1396. Hinquire
  1397.  
  1398. intn Hinquire(int access_id, int32 *pfile_id, uint16 *ptag, uintl6
  1399.        *pref, int32 *plength, int32 *poffset, int32 *pposn, int
  1400.        *paccess, int *pspecial)
  1401.  
  1402.      access_id     IN: Id of an access elt
  1403.      pfile_id     OUT: file id
  1404.      ptag         OUT: tag of the element pointed to
  1405.      pref         OUT: ref of the element pointed to
  1406.      plength      OUT: length of the element pointed to
  1407.      poffset      OUT: offset of elt in the file
  1408.      pposn        OUT: position pointed to within the data elt
  1409.      paccess      OUT: the access type of this access elt
  1410.      pspecial     OUT: special code
  1411.  
  1412.      Purpose:      Returns access information of a data element.
  1413.  
  1414.      Returns:      Returns SUCCEED (0) if the access elt points to
  1415.                    some data element,  otherwise FAIL (-1).
  1416.  
  1417.      Description:  Inquire statistics of the data element pointed
  1418.                    to by access element. If a piece of information
  1419.                    is not needed, it is possible to send NULL in
  1420.                    for that value. There are a set of convenience
  1421.                    macros for calls to Hinquire (HQuerypositon,
  1422.                    HQuerylength, etc ... ) defined in hdf.h.
  1423.  
  1424. Hishdf
  1425.  
  1426. int32 Hishdf(char *Path)
  1427.  
  1428.      path          IN: name of file
  1429.  
  1430.      Purpose:      Determine if a file is an HDF file.
  1431.  
  1432.      Returns:      Returns TRUE (non-zero) if file is HDF, FALSE
  1433.                    (0) otherwise.
  1434.  
  1435.      Description:  The decision of where a file is and HDF file or
  1436.                    not is based solely on the magic number stored
  1437.                    in the first four bytes of an HDF file. It is
  1438.                    possible that Hishdf will identify a file as an
  1439.                    HDF file but Hopen will be unable to open the
  1440.                    file (for example if the DD list in the file is
  1441.                    corrupted).
  1442.  
  1443. Hnumber
  1444.  
  1445. int Hnumber(int32 file-id, uint16 tag)
  1446.  
  1447.      file id       IN: file id
  1448.      tag           IN: tag to be counted
  1449.  
  1450.      Purpose:      Find the number of occurrences of tag/ref in
  1451.                    file.
  1452.  
  1453.      Returns:      The number of instances of a tag in a file.
  1454.  
  1455. Hgetlibversion
  1456.  
  1457. Hgetlibversion--return version info for current HDF library
  1458.  
  1459. USAGE
  1460.  
  1461. Hgetlibversion(uint32 *majorv, uint32 *minorv, uint32 *release,
  1462. char string[])
  1463.  
  1464.      majorv       OUT: majorv version number
  1465.      minorv       OUT: minorv version number
  1466.      release      OUT: release number
  1467.      string       OUT: informational text string (80 chars)
  1468.  
  1469.      Purpose:     Get version information for current HDF library.
  1470.  
  1471.      Returns:     Returns SUCCEED (0).
  1472.  
  1473.      Description: Returns the version of the HDF library. The
  1474.                   version information is statistically compiled
  1475.                   into the HDF library, so it is not necessary to
  1476.                   have any open files for this function to execute.
  1477.  
  1478. Hgetfileversion
  1479.  
  1480. Hgetfileversion--return version info for HDF file
  1481.  
  1482. USAGE
  1483.  
  1484. Hgetfileversion(uint32 file-id, uint32 *majorv, uint32 *minorv,
  1485. uint32 *release, char string[])
  1486.  
  1487.      file_id       IN: handle of file
  1488.      majorv       OUT: majorv version number
  1489.      *minorv      OUT: minorv version number
  1490.      release      OUT: release number
  1491.      string       OUT: Informational text string (80 chars)
  1492.  
  1493.      Purpose:     Get version information for an HDF file.
  1494.  
  1495.      Returns:     Returns SUCCEED (0) if successful and FAIL (-1)
  1496.                   if failed.
  1497.  
  1498.      Description: Returns the HDF version number stored in the
  1499.                   given file. It is still an open question as to
  1500.                   what exactly the version number of a file should
  1501.                   mean, so we recommend that user code not call
  1502.                   this function.
  1503.  
  1504. Reading and Writing Entire Data Elements
  1505.  
  1506. Hputelement
  1507.  
  1508. int Hputelement(int fileid, int tag, int ref,.char *data, long
  1509. length)
  1510.  
  1511.      fileid        IN: Id of file
  1512.      tag           IN: tag of data element to put
  1513.      ref           IN: ref of data element to put
  1514.      data          IN: pointer to buffer
  1515.      length        IN: length of data
  1516.  
  1517.      Purpose:      Add or replace element in a file.
  1518.  
  1519.      Returns:      Returns SUCCEED (0) if successful and FAIL (-1)
  1520.                    otherwise.
  1521.  
  1522.      Description:  Writes a data element or replace an existing
  1523.                    data element in a HDF file. Uses Hwrite and its
  1524.                    associated routines.
  1525.  
  1526. Hgetelement
  1527.  
  1528. int Hgetelement(int file_id, int tag, int ref, char *data)
  1529.  
  1530.      file_id       IN: Id of the file to read from
  1531.      tag           IN: tag of data element to read
  1532.      ref           IN: ref of data element to read
  1533.      data         OUT: buffer to read into
  1534.  
  1535.      Purpose:      Obtains the data referred to by the tag/ref
  1536.                    combination that passed to it.
  1537.  
  1538.      Returns:      Returns SUCCEED (0) if successful, FAIL (-1)
  1539.                    otherwise.
  1540.  
  1541.      Description:  Read in a data element from a HDF file and puts
  1542.                    it into buffer pointed to by data. The space
  1543.                    allocated for buffer is assumed to be large
  1544.                    enough.
  1545.  
  1546. Reading and Writing Part of a Data Element
  1547.  
  1548. Hread
  1549.  
  1550. int32 Hread(int access_id, long length, char *data)
  1551.  
  1552.      access_id     IN: Id of READ access element
  1553.      length        IN: length of segment to read in
  1554.      data         OUT: pointer to data array to read to
  1555.  
  1556.      Purpose:      Read a portion of a data element.
  1557.  
  1558.      Returns:      Returns length of segment actually read in if
  1559.                    successful and FAIL otherwise.
  1560.  
  1561.      Description:  Read in the next segment in the data element
  1562.                    pointed to by .the access element. It starts at
  1563.                    the last position left by a Hread, or Hseek
  1564.                    command and reads any data that remains in the
  1565.                    element up to a specified number of bytes. If
  1566.                    the data element is too short then it only reads
  1567.                    to end of the data element.
  1568.  
  1569. Hwrite
  1570.  
  1571. int32 Hwrite(int access_id, long len, char *data)
  1572.  
  1573.      access_id     IN: Id of WRITE access element
  1574.      len           IN: length of segment to write
  1575.      data          IN:    pointer to data to write
  1576.  
  1577.      Purpose:      Write next data segment to data element.
  1578.  
  1579.      Returns:      Returns length of segment successfully written,
  1580.                    FAIL (-1) otherwise.
  1581.  
  1582.      Description:  Write the data to data element where the last
  1583.                    write or Hseek() stopped. It starts at the last
  1584.                    position left by a Hwrite command, writes up to
  1585.                    a specified number of bytes, then leaves the
  1586.                    write pointer at the end of the element. If the
  1587.                    space reserved is less than the length to write,
  1588.                    then only as much as can fit is written. It is
  1589.                    the responsibility of the user to insure that
  1590.                    no two access elements are writing to the same
  1591.                    data element. It is possible to interlace writes
  1592.                    to more than one data elements in the same file
  1593.                    though.
  1594.  
  1595. Hseek
  1596.  
  1597. intn Hseek(int32 access_id, long offset, int origin)
  1598.  
  1599.      access_id     IN: Id of access element
  1600.      offset        IN: offset to seek to
  1601.      origin        IN: position to seek from by offset, 0: from
  1602.                        beginning; 1: current position; 2: end of
  1603.                        data element
  1604.  
  1605.      Purpose:      Set the access pointer to an offset within a
  1606.                    data element. The next time Hread or Hwrite is
  1607.                    called, the read or write occurs from the new
  1608.                    position.
  1609.  
  1610.      Returns:      Returns FAIL (-1) if fail, SUCCEED (0)
  1611.                    otherwise.
  1612.  
  1613.      Description:  Sets the position of an access element in a data
  1614.                    element that the next Hread or Hwrite will start
  1615.                    from that position. origin determines the
  1616.                    position from which the offset should be added.
  1617.                    This routine fails if the access element is not
  1618.                    associated with any data element and if the
  1619.                    seeked position is outside c the data element.
  1620.  
  1621.                    Seeking from the end of a data element is not
  1622.                    currently supported.
  1623.  
  1624. Manipulating Data Descriptors
  1625.  
  1626. Hdupdd
  1627.  
  1628. int Hdupdd(int32 file_id, uint16 tag, uint16 ref, uint16 old_tag,
  1629. uint16 old_ref)
  1630.  
  1631.      file id       IN: Id of file
  1632.      tag           IN: tag of new data descriptor
  1633.      ref           IN: ref of new data descriptor
  1634.      old_tag       IN: tag of data descriptor to duplicate
  1635.      old_ref       IN: ref of data descriptor to duplicate
  1636.  
  1637.      Purpose:      Generate new references to data that is already
  1638.                    referenced from somewhere else.
  1639.  
  1640.      Returns:      Returns SUCCEED (0) if successful, FAIL (-1)
  1641.                    otherwise.
  1642.  
  1643.      Description:  Duplicates a data descriptor so that the new
  1644.                    tag/ref points to the same data element pointed
  1645.                    to by the old tag/ref.
  1646.  
  1647. Hdeldd
  1648.  
  1649. int Hdeldd(int file_id, int tag, int ref)
  1650.  
  1651.      file id       IN: Id of file
  1652.      tag           IN: tag of data descriptor to delete
  1653.      ref           IN: ref of data descriptor to delete
  1654.  
  1655.      Purpose:      Delete a tag/ref from the list of DDs.
  1656.  
  1657.      Returns:      Returns SUCCEED (0) if successful, FAIL (-1)
  1658.                    otherwise.
  1659.  
  1660.      Description:  Deletes a data descriptor of tag/ref from the
  1661.                    dd list of the file. This routine is unsafe and
  1662.                    may leave a file in a condition that is not
  1663.                    usable by some routines. Use with care.
  1664.  
  1665. Hnewref
  1666.  
  1667. uint16 Hnewref(int32 file_id)
  1668.  
  1669.      file-id       IN: id of file
  1670.  
  1671.      Purpose:      Return the next available ref for HDF file.
  1672.  
  1673.      Returns:      Returns the ref number, 0 otherwise.
  1674.  
  1675.      Description:  Returns a ref number that can be used with any
  1676.                    tag to produce a unique tag/ref. Successive
  1677.                    calls to Hnewref will generate a strictly
  1678.                    increasing sequence until the highest possible
  1679.                    ref had been returned, then Hnewref will return
  1680.                    unused ref's starting from 1.
  1681.  
  1682. Creating Special Data Elements
  1683.  
  1684. HLcreate
  1685.  
  1686. int32 HLcreate(int32 file_id, uint16 tag, uint16 ref, int32
  1687. block_length, int32 number_blocks)
  1688.  
  1689.      file_id       IN: Id of file
  1690.      tag           IN: tag of new data descriptor
  1691.      ref           IN: ref of new data descriptor
  1692.      block_length  IN: length of blocks to be used
  1693.      number-blocks IN: number of blocks to use per linked block
  1694.                        record
  1695.  
  1696.      Purpose:      Create a new linked block special data element.
  1697.  
  1698.      Returns:      Access Id for special data element if
  1699.                    successful, otherwise (-1).
  1700.  
  1701.      Description:  Appending to existing elements has been a
  1702.                    problem in HDF in the past as HDF objects were
  1703.                    required to be stored contiguous. When
  1704.                    appending, the HDF library had forced the
  1705.                    use to delete the existing element and move it
  1706.                    to the end. With HDF 3.2 we had added the
  1707.                    concept of linked blocks which allow unlimited
  1708.                    appending to existing elements without copying
  1709.                    over existing data.
  1710.  
  1711.                    Initially, a table is set up to accommodate
  1712.                    numer_blocks linked blocks for this object. Each
  1713.                    block has size block_length bytes. If an
  1714.                    existing object is being promoted, block_length
  1715.                    does not have to be the same size as the
  1716.                    original element.
  1717.  
  1718.                    This routine can be used to either create an
  1719.                    object with the given tag ref as a linked block
  1720.                    element, or promote an existing element to be
  1721.                    stored with linked blocks. This routine will
  1722.                    return an active access id with write permission
  1723.                    to the linked block element.
  1724.  
  1725. HXcreate
  1726.  
  1727. int32 HXcreate(int32 file_id, uint16 tag, uint16 ref, char
  1728. *extern_file_name)
  1729.  
  1730.      file_id       IN: file record id
  1731.      tag, ref      IN: tag/ref of the special data element to
  1732.                        create
  1733.      extern_file_name
  1734.                    IN: name of external file to use as data element
  1735.  
  1736.      Purpose:      Create a new external file special data element.
  1737.  
  1738.      Returns:      Access id for special data element if
  1739.                    successful, otherwise FAIL (-1).
  1740.  
  1741.      Description:  This routine is used to create a new element in
  1742.                    an external file or promote an existing element
  1743.                    to be in an external file. if an existing
  1744.                    element is to be promoted, it is deleted from
  1745.                    the original file and copied over into the new
  1746.                    external file.
  1747.  
  1748.                    Distributing a single object over multiple
  1749.                    external files is currently not supported. In
  1750.                    addition, it is not possible to place multiple
  1751.                    objects into the same external file. This
  1752.                    routine will return an active access id with
  1753.                    write permission to the external element.
  1754.  
  1755. Development Routines
  1756.  
  1757. HDgettagname
  1758.  
  1759. char *HDgettagname(uint16 tag)
  1760.  
  1761.      tag           IN: tag to look up
  1762.  
  1763.      Purpose:      Get a meaningful description of a tag.
  1764.  
  1765.      Returns:      A pointer to a string describing this tag or
  1766.                    NULL if the tag unknown.
  1767.      Description:  To reduce on the amount of reduplicated code,
  1768.                    this rout can be used to map a tag to a
  1769.                    character string containing the name of the tag.
  1770.                    If the tag is unknown, NULL is returned as
  1771.                    programs may have different ways of dealing with
  1772.                    unknown tags
  1773.  
  1774.                    For formatting purposes, the string returned by
  1775.                    this routine guaranteed to be 30 characters or
  1776.                    less.
  1777.  
  1778. HDgetspace
  1779.  
  1780. void *HDgetspace(uint32 qty)
  1781.  
  1782.      qty           IN: number of bytes to allocate
  1783.  
  1784.      Purpose:      Allocate space.
  1785.  
  1786.      Returns:      Pointer to space that was allocated.
  1787.  
  1788.      Description:  This routine is very platform-dependent. It uses
  1789.                    an appropriate allocation routine on the local
  1790.                    machine to get space
  1791.  
  1792. HDfreespace
  1793.  
  1794. void *HDfreespace(void *ptr)
  1795.  
  1796.      ptr           IN: pointer to previously-allocated space to be
  1797.                        freed
  1798.  
  1799.      Purpose:      Free space.
  1800.  
  1801.      Returns:      NULL.
  1802.  
  1803.      Description:  It uses an appropriate routine on the local
  1804.                    machine to space.
  1805.  
  1806. HDstrncpy
  1807.  
  1808. char *HDstrncpy(register char *dest,register char *source,int32
  1809. len)
  1810.  
  1811.      dest         OUT: pointer to area to copy string to
  1812.      src           IN: pointer to area to copy string from
  1813.      len           IN: maximum number.of bytes to copy
  1814.  
  1815.      Purpose:      Copy a string with some maximum length.
  1816.  
  1817.      Returns:      Address of dest.
  1818.  
  1819.      Description:  This function creates a string in dest that is
  1820.                    at most len' characters long. The `len'
  1821.                    characters include the NULL terminator, which
  1822.                    must be added for historical reasons. Hence, if
  1823.                    you have the string 'Foo\0' you must call this
  1824.                    copy function with len = 4
  1825.  
  1826. Error Reporting
  1827.  
  1828. HEprint
  1829.  
  1830. void HEprint(FILE *stream, int level)
  1831.  
  1832.      stream        IN: stream to print error messages on
  1833.      level         IN: level of the error stack to print
  1834.  
  1835.      Purpose:      Print out information on the error stack.
  1836.  
  1837.      Returns:      No return value.
  1838.  
  1839.      Description:  This routine will print out information on
  1840.                    reported errors. If level is zero all of the
  1841.                    errors currently on the error stack are printed.
  1842.                    Output of this function is sent to the file
  1843.                    point to by stream.
  1844.  
  1845.                    Information printed is: an ascii description of
  1846.                    the error, the reporting routine, its file name
  1847.                    and the line at which the error was reported.
  1848.                    In addition, if the programmer has supplied
  1849.                    extra information by means of HEreport, this
  1850.                    information is printed well.
  1851.  
  1852. HEclear
  1853.  
  1854. void HEclear(void)
  1855.  
  1856.      Purpose:      Clear all information on reported errors off of
  1857.                    the error stack
  1858.  
  1859.      Returns:      No return values.
  1860.  
  1861.      Description:  Clear all of the information off of the error
  1862.                    stack.
  1863.  
  1864. HERROR
  1865.  
  1866. void HERROR(int number)
  1867.  
  1868.      number        IN: error number
  1869.  
  1870.      Purpose:      Report an error.
  1871.  
  1872.      Returns:      No return value.
  1873.  
  1874.      Description:  HERROR can be used to report an error. Any
  1875.                    function which calls HERROR must have a variable
  1876.                    FUNC which points to a string containing the
  1877.                    name of the function.
  1878.  
  1879.                    HERROR is implemented as a macro.
  1880.  
  1881. HEreport
  1882.  
  1883. void HEreport(char *format, ... )
  1884.  
  1885.      format        IN: printf style format and arguments
  1886.  
  1887.      Purpose:      Provide extra information to the error reporting
  1888.                    routines.
  1889.  
  1890.      Returns:      No return value.
  1891.  
  1892.      Description:  This routine can be used to provide further
  1893.                    annotation to an error report. Only one such
  1894.                    annotation is remembered for each error report.
  1895.                    The arguments to this routine follow the style
  1896.                    of printf.
  1897.  
  1898.                    An example from hfile.c
  1899.  
  1900.                    char *FUNC = "Hclose";
  1901.                    ...
  1902.                    if (file_rec->attach > 0) {
  1903.                          file rec>refcount++;
  1904.                          HERROR(DFE_OPENAID);
  1905.                          HEreport("There are still %d active aids
  1906.                          attached",
  1907.                          file rec->attach)
  1908.                          return FAIL;
  1909.  
  1910. Other
  1911.  
  1912. Hsync
  1913.  
  1914. int Hsync(int32 file id)
  1915.  
  1916.      file_id       IN: id of the file to sync
  1917.  
  1918.      Purpose:      Synchronize on-disk HDF file with image in
  1919.                    memory.
  1920.  
  1921.      Returns:      Returns SUCCEED.
  1922.  
  1923.      Description:  This routine is currently vacuous as the on-disk
  1924.                    representation of an HDF file is always the same
  1925.                    as its in-me representation. However, future
  1926.                    releases of the HDF library n employ buffering
  1927.                    schemes, so this might not always be the case.
  1928.                    Hsync will be provided to force the two
  1929.                    representations to be consistent.
  1930.  
  1931.  
  1932. Chapter 4      Sets and Groups
  1933.  
  1934.                Chapter Overview
  1935.                Sets
  1936.                    Types of Sets
  1937.                    Calling Interfaces for Sets
  1938.                Groups
  1939.                    Sample Groups
  1940.                    General Features of Groups
  1941.                Raster Image Sets
  1942.                    Raster Image Groups
  1943.                    Tags for Raster Image Sets
  1944.                    Compression of Raster Images
  1945.                Scientific Datasets
  1946.                    Required Tags
  1947.                    Optional Tags
  1948.                Vsets and Vdatas
  1949.                Chapter Appendix: Raster-8 Sets
  1950.                    Compatibility between Raster-8 and Raster Image Sets
  1951.  
  1952.  
  1953. Chapter Overview
  1954.  
  1955. This chapter describes raster image sets, scientific datasets and
  1956. Vsets, and explains the role of sets and groups in an HDF file. It
  1957. also discusses the programming interfaces available for the three
  1958. types of sets.
  1959.  
  1960. Sets
  1961.  
  1962. Sometimes tags are grouped into sets, where each set is designed
  1963. to serve a particular user requirement. For example, the raster
  1964. image set that is described in the following sections, contains
  1965. several tags that are used for storing information about 8-bit
  1966. raster images.
  1967.  
  1968. Types of Sets
  1969.  
  1970. In the current implementation of HDF there are three kinds of sets:
  1971.  
  1972. * A raster image set contains a raster image, along with
  1973.   descriptive information about the image, such as its dimensions
  1974.   and (optionally) a color lookup table.
  1975.  
  1976. * A scientific data set contains a multidimensional array, along
  1977.   with descriptive information about the data.
  1978.  
  1979. * A Vset is a general grouping structure that can contain any kinds
  1980.   of HDF objects that a user wishes.
  1981.  
  1982. Each HDF set is defined in terms of a minimum collection of data
  1983. objects that must be present for the set to make sense when it is
  1984. used. For instance, every raster image set must contain at least
  1985. the following three data objects:
  1986.  
  1987. * an image dimension record, which gives the width and height of
  1988.   the corresponding image;
  1989.  
  1990. * raster image data, which consists of the pixel values that make
  1991.   up the image;
  1992.  
  1993. * a raster image group, which lists all of the members in the set.
  1994.  
  1995. In addition to the required objects, there are optional data
  1996. objects that may be included in a set. A raster image set, for
  1997. instance, often contains a palette, or color lookup table, which
  1998. gives the red, green, and blue values to be associated with each
  1999. pixel in the raster image data.
  2000.  
  2001. Calling Interfaces for Sets
  2002.  
  2003. NCSA provides calling interfaces for all the HDF sets that it
  2004. supports. The primary purpose of these calling interfaces is to
  2005. provide libraries of routines for reading and writing the data that
  2006. is associated with each set. The libraries currently supported at
  2007. NCSA are callable from either C or Fortran programs.
  2008.  
  2009. In addition to the libraries, a growing number of command-line
  2010. utility routines are available for working with sets. For example,
  2011. a utility called r8tohdf is an HDF command that converts one or
  2012. more raw raster images to HDF 8-bit raster image set format.
  2013.  
  2014. NCSA supports calling interfaces for the following machines: Cray
  2015. (UNICOS), Silicon Graphics (UNIX), Sun (UNIX), Macintosh (MacOS),
  2016. and IBM PC (MS-DOS). The calling interfaces that are currently
  2017. available are described in the manual NCSA HDF Calling Interfaces
  2018. and Utilities.
  2019.  
  2020. Groups
  2021.  
  2022. An HDF set is a collection of HDF data objects in a file. Unless
  2023. some mechanism is used to identify explicitly those objects that
  2024. belong to a set, there is often no way to tie them together. This
  2025. problem is solved in HDF by means of groups. A group is a data
  2026. object that explicitly identifies all of the data objects in a set.
  2027.  
  2028. Since a group is a type of data object, its structure is like that
  2029. of any other data object. A group data identifier (tag/ref) points
  2030. to a data element that consists of the collection of data
  2031. identifiers that make up the corresponding set. A group tag can be
  2032. defined for any set. For instance, raster image group (RIG) is the
  2033. group tag used to group members of raster image sets; RIG data
  2034. consists of a list of all data identifiers that belong to a
  2035. particular raster image set.
  2036.  
  2037. Groups provide a convenient mechanism for. application programs to
  2038. locate all of the information that they need about a set.
  2039. Application programs that deal with RIGs, for instance, read all
  2040. of the elements in a RIG group, using only those that they need for
  2041. their application and ignoring the others.
  2042.  
  2043. Sample Groups
  2044.  
  2045. Suppose that the two images shown in Figure 1.5 are organized into
  2046. two sets with group tags. Since they are images, they may be stored
  2047. as RIG groups. Figure 4.1 illustrates the type of organization that
  2048. incorporates RIG groupings of these images.
  2049.  
  2050. Figure 4.1  Physical Organization of Sample RIG Grouping
  2051.  
  2052. Offset         Contents
  2053.    0      FH
  2054.    4      DDH       (10       OL)
  2055.   10      DD        (FID      1         130       4)
  2056.   22      DD        (FD       1         134       41)
  2057.   34      DD        (IP8      1         175       768)
  2058.   46      DD        (ID       1         943       4)
  2059.   58      DD        (RI       1         947       240000)
  2060.   70      DD        (ID       2         240947    4)
  2061.   82      DD        (RI       2         240951    240000)
  2062.   94      DD        (RIG      1         480951    12)
  2063.  106      DD        (RIG      2         480963    12)
  2064.  118      DD        (empty)
  2065.  130      "sw3"
  2066.  134      "solar wind simulation: third try. 8/8/88"
  2067.  175      <data for image palette>
  2068.  943      <data for 1st image dimension rec>: 400, 600
  2069.  947      <data for 1st raster image>
  2070. 240947    <data for 2nd image dimension rec>: 400, 600
  2071. 240951    <data for 2nd raster image>
  2072. 480951    tag/refs for 1st RIG: IP8/1, ID/1, RI/1
  2073. 480963    tag/refs for 2nd RIG: IP8/1, ID/2, RI/2
  2074.  
  2075. The structure depicted in Figure 4.1 reflects the grouping of
  2076. raster image sets. This file contains the same raster image
  2077. information as the file in Figure 1.5, but the information is
  2078. organized into two sets and groups. Note that there is only one
  2079. palette (IP8/1) and it is included in both groups.
  2080.  
  2081. General Features of Groups
  2082.  
  2083. Figure 4.1 also illustrates a number of important general features
  2084. of groups:
  2085.  
  2086. * The contents of each set are consistent with one another. Since
  2087.   the palette (IP8) is designed for use with 8-bit images, the
  2088.   image must be an 8-bit image, rather than a 24-bit, 12-bit, or
  2089.   other image.
  2090.  
  2091. * An application program can easily process all of the images in
  2092.   the file by accessing the groups in the file. The non-RIG
  2093.   information contained in the file can be used or ignored,
  2094.   depending on the needs and capabilities of the application
  2095.   program.
  2096.  
  2097. * There is usually more than one way to group sets. For example,
  2098.   an extra copy of the image palette (IP8) could have been stored
  2099.   in the file, so that each grouping would have its own image
  2100.   palette. But in this instance that is not necessary because the
  2101.   same palette is to be used with both images. On the other hand,
  2102.   in this example there are two image dimension records (one per
  2103.   group), even though one would suffice.
  2104.  
  2105. * Group status does not alter the fundamental role of HDF objects.
  2106.   They are still accessible as individual data objects, despite the
  2107.   fact that they also belong to raster image sets. In a very real
  2108.   sense, the individual data elements are in the file, whether or
  2109.   not there are groups that contain them.
  2110.  
  2111.   RIGs provide an index showing what sets exist and what their
  2112.   members are. There is nothing to prevent the imposition of other
  2113.   groupings (indexes) that provide a different view of the same
  2114.   collection of data objects. In fact, HDF is designed to encourage
  2115.   the addition of alternate views, when appropriate.
  2116.  
  2117. Raster Image Sets
  2118.  
  2119. The raster image set (RIS) provides a framework for storing images
  2120. and any number of optional image descriptors. It provides for a
  2121. description of the image data layout, with the optional presence
  2122. of color look-up tables, aspect ratio, color correction, associated
  2123. matte or other overlay information, or any other data related to
  2124. the display of the image.
  2125.  
  2126. Raster Image Groups (RIGs)
  2127.  
  2128. Tying everything together is the raster image group (RIG), examples
  2129. of which were given earlier (Figure 4.1) A RIG contains a list of
  2130. data identifiers that point in turn to the data objects that
  2131. describe and make up the image.
  2132.  
  2133. The number of entries in a RIG is variable and the presence of most
  2134. of the description information is optional. Complex applications
  2135. can store data identifiers of image-modifying data, such as the
  2136. color table and aspect ratio, in the RIG along with the reference
  2137. to the image data itself. Simple applications can use simple
  2138. application level calls and ignore specialized video production or
  2139. film color correction parameters.
  2140.  
  2141. NCSA currently supports two calling interfaces, RIS8 and RIS24,
  2142. defined for the easy storage and retrieval of raster images using
  2143. RIGS. These interfaces are documented in the manual NCSA HDF
  2144. Calling interfaces and Utilities
  2145.  
  2146. Tags for Raster Image Sets
  2147.  
  2148. The tags presented in Table 4.1 must be fully supported by any
  2149. raster image set implementation.
  2150.  
  2151. Table 4.1  Tags for Raster Image Sets
  2152.  
  2153. Tag            Contents of Data Element
  2154.  
  2155. RIG            raster image group
  2156. ID             image dimension record
  2157. RI             raster image data
  2158.  
  2159. With full support for the above tags, images can be stored and read
  2160. from HDF files at any bit depth, with several different component
  2161. ordering schemes. As illustrated in Fig. 4.1, the RIG tag points
  2162. to a collection of the tag/refs that make up the RIG. The ID data
  2163. element identifies the dimensions of the image, the number type of
  2164. the elements that make up its pixels, the number of elements per
  2165. pixel, the interlace scheme used and the compression scheme used,
  2166. if any. The RI data element contains the actual raster image data.
  2167.  
  2168. *** INSERT FIGURE HERE ***
  2169.  
  2170. In addition to the required tags that define an image dataset, the
  2171. tags listed in Table 4.2 define color properties and other image
  2172. features. These tags are described fully in Appendix A.
  2173.  
  2174. Table 4.2  Additional Tags for Raster Image Sets
  2175.  
  2176. Tag            Contents of Data Element
  2177. XYP            XY position of image
  2178. LD             look-up table dimension record
  2179. LUT            color look-up table for non true-color Images
  2180. MD             matte channel dimension record
  2181. MA             matte channel data
  2182. CCN            color correction factors
  2183. CFM            color format designation
  2184. AR             aspect ratio
  2185. MTO            machine-type override
  2186.  
  2187. Fig. 4.2 illustrates the storage of a RIS that contains an image
  2188. palette (IP8), in addition to the required tags.
  2189.  
  2190. *** INSERT FIGURE HERE ***
  2191.  
  2192. Compression of Raster Images
  2193.  
  2194. Tags for two types of compression have been defined for raster
  2195. images. They are run-length encoding (RLE) and IMCOMP aerial
  2196. averaging (IMC). Others may be added at any time. Each encoding tag
  2197. is documented under its specific tag type (see Appendix A). Support
  2198. for RIG and RI does not require that all of the compression tag
  2199. types be supported. If you find an unknown compression type,
  2200. provide a suitable error message to the user.
  2201.  
  2202. Scientific Datasets
  2203.  
  2204. The scientific dataset (SDS) provides a framework for storing
  2205. multidimensional arrays of data, together with descriptive
  2206. information about the data. Current specifications support the
  2207. following types of numbers in SDS arrays.
  2208.  
  2209. * 8-bit, 16-bit and 32-bit signed and unsigned integers
  2210. * 32-bit and 64-bit floating point numbers
  2211.  
  2212. SDS numbers can be stored either as IEEE Standard integers or
  2213. floats or in the format used by the machine from which they were
  2214. written ("native mode").
  2215.  
  2216. Rank and dimension sizes may vary. A user interface exists for
  2217. storing and retrieving SDS. See the NCSA HDF manual for details.
  2218.  
  2219. Internal structures
  2220.  
  2221. For reasons having to do with backward compatibility, the group
  2222. structure that HDF uses for SDS is complicated. HDF 3.1 and
  2223. previous versions only supported 32-bit IEEE floating-point numbers
  2224. and Cray floating point numbers in' scientific data sets. HDF 3.2
  2225. and later releases support 8-bit, 16-bit, and 32-bit signed and
  2226. unsigned integers, and 32-bit and 64-bit floating-point numbers.
  2227. It also allows data sets to be written to HDF files in the local
  2228. machine format ("native mode"). Furthermore, it is anticipated that
  2229. later versions of HDF will support new number types and other
  2230. variations in the physical storage of scientific data, such as
  2231. compressed data.
  2232.  
  2233. The internal structure used to store SDS in HDF 3.1 and earlier
  2234. versions was not adequate to support the anticipated future changes
  2235. to SDS. A new structure had to be developed. At the same time, it
  2236. was important to try to retain compatibility with earlier versions
  2237. of the HDF library. Earlier versions of the library should be able
  2238. to read SDS written by HDF 3.2, if the SDS is "understandable" by
  2239. that earlier software, i.e. if the number type of the data is 32-
  2240. bit IEEE floating point or Cray floating point. Likewise, new
  2241. libraries (HDF 3.2 and beyond) should be able to recognize SDS
  2242. written by earlier versions of the library.
  2243.  
  2244. This compatibility is achieved by examining every SDS that is
  2245. written to an HDF file. If the SDS is compatible with older
  2246. libraries, it is written to the file using the old structure used
  2247. to represent SDS, as well as the new structure. If it is not
  2248. compatible with older libraries, only the newer structure is used.
  2249.  
  2250. The old structure for storing SDS is called SDG ("scientific data
  2251. group"). The newer structure is called NDG ("numeric data group").
  2252. Hence, SDS user interfaces in HDF3.2 and beyond handle three types
  2253. of numerical data groups:
  2254.  
  2255. 1. SDG-created by old libraries and containing floating-point data.
  2256.  
  2257. 2. NDG-created by the new library and containing non-floating-point
  2258.    data. This data group should not be recognized by old libraries.
  2259.  
  2260. 3. SDG-like NDG-created by the new library and containing IEEE
  2261.    32-bit floating-point data only. The old libraries should be
  2262.    able to recognize and interpret this kind of numerical data
  2263.    groups correctly.
  2264.  
  2265.  
  2266. In the following sections, we described the SDG and NDG grouping
  2267. structures.
  2268.  
  2269. SDG structure
  2270.  
  2271.     Scientific datasets represented internally by the SDG tag must
  2272. always contain at least the data objects listed in Table 4.3.
  2273.  
  2274. Table 4.3  Required Tags for SDG
  2275.  
  2276. Tag            Contents of Data Element
  2277.  
  2278. SDG            scientific data group
  2279.  
  2280. SDD            scientific data dimension record for array-
  2281.                stored data. It includes the rank (number of
  2282.                dimensions) the size of each dimension, the
  2283.                tag/ref's representing the number types of the
  2284.                array-stored data and of each dimension.
  2285.  
  2286.                In the case of SDG, the number types are all
  2287.                32-bit IEEE floating-point values.
  2288.  
  2289. SD             scientific data
  2290.  
  2291. The data objects presented in Table 4.4 are optional.
  2292. NCSA's SDS user interface supports these objects
  2293.  
  2294. Table 4.4  Optional Tags for SDG
  2295.  
  2296. Tag            Contents of Data Element
  2297.  
  2298. SDS            scales along the different dimensions to be
  2299.                used when interpreting or displaying the data
  2300.                (must be of type float32).
  2301.  
  2302. SDL            labels for all dimensions and for the data.
  2303.                Each of the dimension labels can be interpreted
  2304.                as an independent variable, and the data label
  2305.                as the dependent variable.
  2306.  
  2307. SDU            units for all dimensions and for the data.
  2308.  
  2309. SDF            format specifications to be used when
  2310.                displaying values of the data.
  2311.  
  2312. SDM            maximum and minimum values of the data (must be
  2313.                of type float32).
  2314.  
  2315. SDC            coordinate system to be used when interpreting
  2316.                or displaying the data.
  2317.  
  2318. As illustrated in Fig. 4.3, the SDG tag points to a collection of
  2319. the tag/refs that make up the SDG.
  2320.  
  2321. *** INSERT FIGURE HERE  ***
  2322.  
  2323.  
  2324. NDG structure
  2325.  
  2326. SDS represented internally by the NDG tag must always contain at
  2327. least the data objects listed in Table 4.5
  2328.  
  2329. Table 4. 5  Required Tags for NDG
  2330.  
  2331. Tag            Contents of Data Element
  2332.  
  2333. NDG            Numerical data group
  2334.  
  2335. SDD            Scientific data dimension record for array-
  2336.                stored data. It includes the rank (number of
  2337.                dimensions), the size of each dimension, the
  2338.                tag/ref's representing the number types of the
  2339.                array-stored data and of each dimension.
  2340.  
  2341.                In HDF 3.2 , the number types of dimension
  2342.                scales are forced to be the same as the array-
  2343.                stored data, but in later implementations each
  2344.                dimension scale will be allowed its own type.
  2345.  
  2346. SD             Scientific data.
  2347.  
  2348. NT             Number type of the data set. Default of NT is
  2349.                the value most recently set by DFSDsetNT(). If
  2350.                no DFSDsetNT() was called previously, the
  2351.                default will be set as floating-point.
  2352.  
  2353. The data objects presented in Table 4.6 are optional. NCSA's SDS
  2354. user interface in HDF 3.2 and later versions supports these
  2355. objects. Other optional objects can be added at any time.
  2356.  
  2357. Table 4.6  Optional Tags for NDG, HDF 3.2.
  2358.  
  2359. Tag            Contents of Data Element
  2360.  
  2361. SDS            scales along the different dimensions to be
  2362.                used when interpreting or displaying the data..
  2363.  
  2364. SDL            labels for all dimensions and for the data.
  2365.                Each of the dimension labels can be interpreted
  2366.                as an independent variable, and the data label
  2367.                as the dependent variable.
  2368.  
  2369. SDU            units for all dimensions and for the data.
  2370.  
  2371. SDF            format specifications to be used when
  2372.                displaying values of the data.
  2373.  
  2374. SDM            maximum and minimum values of the data.
  2375.  
  2376. SDC            coordinate system to be used when interpreting
  2377.                or displaying the data.
  2378.  
  2379. As illustrated in Fig. 4.4, the NDG is identical to the SDG, except
  2380. that the NDG tag is different. This insures that older (pre-HDF
  2381. 3.2) software cannot recognize this form of SDS.
  2382.  
  2383. *** INSERT FIGURE HERE ***
  2384.  
  2385. SDG-like NDG structure
  2386.  
  2387. An SDS written by HDF 3.2 or later that is compatible with earlier
  2388. SDS is represented internally by both an SDG and an NDG. Table 4.7
  2389. lists the objects that this group must always contain.
  2390.  
  2391. Table 4.7  Required Tags for NDG structure that is compatible with
  2392. SDG structure
  2393.  
  2394. Tag            Contents of Data Element
  2395.  
  2396. NDG            Numerical data group
  2397.  
  2398. SDG            Scientific data group
  2399.  
  2400. SDLNK          The NDG and SDG linked to the scientific data
  2401.                set in this group.
  2402.  
  2403. SDD            Scientific data dimension record for array-
  2404.                stored data. It includes the rank (number of
  2405.                dimensions), the size of each dimension, the
  2406.                tag/ref's representing the number types of
  2407.                the array-stored data and of each dimension.
  2408.  
  2409.                In an SDG-like NDG the number types are all
  2410.                32-bit IEEE floating-point values.
  2411.  
  2412. SD             Scientific data
  2413.  
  2414. *** INSERT FIGURE HERE ***
  2415.  
  2416.  
  2417. Compatibility with future NDG structures
  2418.  
  2419. It is likely that future versions of SDS will support optional
  2420. features that are not supported by the current version. These
  2421. features fall into two general categories:
  2422.  
  2423. * optional-compatible features: optional features that are
  2424.   compatible with older versions of HDF even though they may not
  2425.   be supported by older versions of HDF.
  2426.  
  2427. * For example, suppose a new attribute such as a time stamp, is
  2428.   added to SDS. Such an attribute would not be "understood" by
  2429.   older libraries, but it would not render the SDS data unreadable
  2430.   by the older libraries.
  2431.  
  2432. * Optional-incompatible features: optional new features that might
  2433.   not be compatible with older versions of HDF in the sense that
  2434.   they could render the data unreadable by older HDF libraries.
  2435.  
  2436.   For example, suppose compression is added to SDS. Since some
  2437.   older HDF libraries contain no compression routines, they would
  2438.   not be able to read the compressed data correctly.
  2439.  
  2440. The scheme that has been developed to address this problem involves
  2441. numbering conventions for tags. The following conventions are used:
  2442.  
  2443. * Required tags. These tags are described in Tables 4.4 and 4.5.
  2444.   All SDS must contain all of the tags in at least one of these
  2445.   sets.
  2446.  
  2447. * Optional-compatible tags. These tags can have any valid tag
  2448.   number except those in the other two categories.
  2449.  
  2450. * Optional-incompatible tags. A range of tags is defined for SDS
  2451.   features that might render the dataset unreadable by older
  2452.   versions of the library. This range has been specified as tag
  2453.   numbers 780-799.
  2454.  
  2455. Vsets and vdatas
  2456.  
  2457. An HDF Vset is a logical grouping of HDF data objects within an
  2458. HDF file. Data organization within the file resembles the UNIX file
  2459. system in that it is basically hierarchical in structure and also
  2460. allows cross-linking of data objects. Unlike Scientific Data Sets
  2461. and Raster Image Sets, Vsets have no prespecified content or
  2462. structure. Users can use them to create structural relationships
  2463. among HDF objects according to their needs. Figure 4.6 illustrates
  2464. a Vset.
  2465.  
  2466. *** INSERT FIGURE HERE ***
  2467.  
  2468. A Vset is represented by a vgroup, an HDF object that contains
  2469. information about the members of the Vset. The vgroup tag is
  2470. VGDESCTAG. The VGDESCTAG record contains a list of the data
  2471. identifiers of its members, an optional user-specified name, an
  2472. optional user-specified class, and some fields that enable it to
  2473. be extended to contain more information. The VGDESCTAG is described
  2474. fully in Appendix A. A full treatment of Vsets can be found in the
  2475. manual "NCSA HDF Vset, Version 2.0".
  2476.  
  2477. An HDF object that is often used in connection with Vsets is the
  2478. vdata. A vdata is a table. The data in a vdata is organized into
  2479. fields. Each field is identified by a unique fieldname. The type
  2480. of each field may be any of the data types supported by the SDS
  2481. interface: 8-, 16-, and 32-bit integers (signed or unsigned), and
  2482. 32- and 64-bit floats. Several fields of different types may exist
  2483. within a vdata. appendix A contains full descriptions of the vdata
  2484. tags (VSDESCTAG and VSDATATAG). A full treatment of vdatas can be
  2485. found in the manual "NCSA HDF vset, Version 2.0".
  2486.  
  2487. Chapter Appendix: The Raster-8 Set
  2488.  
  2489. The raster image set (RIS), as described above, is the set
  2490. currently supported by HDF for managing raster images. Before the
  2491. RIS was added to HDF, a simpler, less flexible set called the
  2492. raster-8 set was used for storing 8-bit raster images. This set is
  2493. no longer supported in the HDF software, although it may turn up
  2494. in some older HDF files. In fact, during the first three years that
  2495. RIS was used, the HDF software stored raster images in both RIS
  2496. and raster-8 sets.
  2497.  
  2498. Raster-8 Sets
  2499.  
  2500. The raster-8 set is a set of tags that provide the basic
  2501. information necessary to store 8-bit raster images in a data file
  2502. and display them accurately without prompting the user to supply
  2503. dimensions or color information. The raster-8 set consists of the
  2504. tags presented in Table 4.8.
  2505.  
  2506. Table 4.8  Tags for Raster-8 Sets
  2507.  
  2508. Tag            Contents of Data Element
  2509.  
  2510. RI8            eight-bit raster image data
  2511.  
  2512. CI8            eight-bit raster image data compressed with
  2513.                run-length encoding
  2514.  
  2515. II8            IMCOMP compressed image data
  2516.  
  2517. ID8            Image dimension record
  2518.  
  2519. IP8            Image palette data
  2520.  
  2521. If you develop software for processing raster-8 sets, it must
  2522. support RI8, ID8, and IP8. If you do not implement CI8 or II8, then
  2523. be sure to provide appropriate error indicators to higher layers
  2524. that might expect to find these tags.
  2525.  
  2526. Compatibility between Raster-8 and Raster Image Sets
  2527.  
  2528. In order to maintain backward compatibility with raster-8 sets,
  2529. raster image set interface has stored tag/refs for both types of
  2530. sets in HDF raster image files. For example, if an image is stored
  2531. as part of a raster image set, there was one copy each of the image
  2532. dimension data, image data, and palette data stored, but there were
  2533. two sets of tag/refs pointing to each data element, one from each
  2534. set. The image data, for instance, was associated with tag RI8 and
  2535. RI.
  2536.  
  2537. NOTE: Although this policy is continued in the current release (HDF
  2538. 3.2), future plans call for phasing out the use of the raster-8
  2539. structure. Therefore, future software should not expect to find
  2540. both raster-8 and RIS structures supporting 8-bit raster images.
  2541. Only RIS structures will eventually be used exclusively.
  2542.  
  2543.  
  2544. Chapter 5      Annotations
  2545.  
  2546.                Chapter Overview
  2547.                Types of Annotations
  2548.                File Annotations
  2549.                Object Annotations
  2550.                Getting Reference Numbers for Object Annotations
  2551.  
  2552.  
  2553. Chapter Overview
  2554.  
  2555. This chapter introduces and describes HDF objects that can be used
  2556. to annotate HDF files and HDF objects..
  2557.  
  2558. Types of Annotations
  2559.  
  2560. It is often useful to associate in text form information about an
  2561. HDF file and its data contents, and to keep that information in the
  2562. same file that contains the data. HDF provides this capability in
  2563. the form of annotations. An HDF annotation is a sequence of ASCII
  2564. characters that is associated its one of three types of objects:
  2565. (1) the file itself, (2) the individual HDF data objects in the
  2566. file, or (3) the tags that identify the data elements. The current
  2567. annotation interface supports only the first two types of
  2568. annotation. This interface is described in detail in the manual
  2569. NCSA RDF Calling Interfaces and Utilities..
  2570.  
  2571. Annotations are optionally supplied by a creator or user of an HDF
  2572. file or data object. Annotations come in two forms: labels, which
  2573. normally consist of short strings of characters, and descriptions,
  2574. which can be long and complex bodies of text.
  2575.  
  2576. Table 5.1 shows the types of annotations currently defined for HDF
  2577. files and their tag names.
  2578.  
  2579. Table 5.1  HDF Annotation tags
  2580.  
  2581.                            "Label"        "Description"
  2582.  
  2583. File Annotations             FID               FD
  2584. Object Annotations           DIL              DIA
  2585. Tag Annotations              TID               TD
  2586.  
  2587. File Annotations
  2588.  
  2589. Any HDF file can have labels (FID) and descriptions (FD)stored in
  2590. them.. There are routines in the annotations interface specifically
  2591. designed for reading and writing file IDs and file descriptions.
  2592. Specifications for the tags FID and FD are given in Appendix A.
  2593.  
  2594. Object Annotations
  2595.  
  2596. The annotation of HDF data objects is complicated by the fact that
  2597. you have to uniquely identify the objects being annotated. Since
  2598. a data identifier (tag/ref) for a data object uniquely identifies
  2599. that object, the data object that a particular annotation refers
  2600. to can be identified by storing the object's tag and reference
  2601. number together with the annotation.
  2602.  
  2603. Note that an RDF annotation is itself a data object, so it has its
  2604. own DD. This DD has a tag and a ref. number, and it points to the
  2605. "data" that constitutes the annotation. The "data" that goes with
  2606. an annotation consists of three things: (1) the tag of the object
  2607. that it is an annotation for, (2) the ref of the object that it is
  2608. an annotation for, and (3) the annotation itself.
  2609.  
  2610. For example, suppose you have an HDF file that contains three
  2611. scientific datasets (SDS). Each SDS has its own DD consisting of
  2612. the SDS tag DFTAG-STG, and a unique reference number as illustrated
  2613. in Figure 5.1.
  2614.  
  2615. *** INSERT FIGURE HERE ***
  2616.  
  2617. Suppose you wish to annotate the second SDS by storing the
  2618. following annotation with it in the file: "Data from black hole
  2619. experiment 8/18/87." This text would be stored in an HDF file as
  2620. an annotation, and it would have stored with it the tag DFTAG-SDG
  2621. and reference number 4. Figure 5.2 illustrates how the annotation
  2622. would look in the file.
  2623.  
  2624. *** INSERT FIGURE HERE ***
  2625.  
  2626. Getting Reference Numbers for Object Annotations
  2627.  
  2628. Note that in order to use annotation routines, you need to know
  2629. the tags and reference numbers of the objects you wish to annotate.
  2630.  
  2631. Special routines are available for obtaining the reference numbers
  2632. of certain tags, including tags for SDSs, Raster Image Sets,
  2633. palettes, and annotations. These are: DFSD1astref, DFR81astref,
  2634. DFP1astref, and DFAN1astref. They return the most recent reference
  2635. number used in either reading or writing the corresponding data
  2636. object. Reference numbers for objects other than these can be
  2637. obtained with the routine Hfindnextref, a general purpose HDF
  2638. routine that searched through an HDF file for reference numbers
  2639. that go with a given tag. These routines are described and
  2640. illustrated in the manual "NCSA HDF Calling Interfaces and
  2641. Utilities."
  2642.  
  2643.  
  2644. Chapter 6      NCSA HDF Tags
  2645.  
  2646.                Chapter Overview
  2647.                The HDF Tag Space
  2648.                Physical Storage Methods
  2649.                Specifications of Supported Tags
  2650.  
  2651.  
  2652. Chapter Overview
  2653.  
  2654. This chapter addresses issues related to HDF tags and the data they
  2655. represent. The first section discusses some general information
  2656. about tags and their interpretation. The remainder of the chapter
  2657. contains a complete list of HDF tags that have been assigned by
  2658. NCSA as of version 3.2 of the library and a detailed discussion of
  2659. their specifications.
  2660.  
  2661. The HDF Tag Space
  2662.  
  2663. As discussed in the chapter entitled "The Basic Structure of HDF
  2664. Files," there are 16 bits allotted to an HDF tag number, providing
  2665. for 65535 possible tags ranging from 1 to 65535, with zero (0)
  2666. unused. This tag space is broken down into three ranges as shown
  2667. below.
  2668.  
  2669.            1--32767 reserved for NCSA-supported tags
  2670.        32768--64999 user-definable
  2671.        65000--65535 reserved for expansion of the format
  2672.  
  2673. No restrictions are placed on the user-definable tags, but it
  2674. should be noted that tags from this range cannot be guaranteed to
  2675. be unique across all user-developed HDF applications. The rest of
  2676. this chapter will be devoted to the NCSA-supported tags in the
  2677. range 1 to 32767.
  2678.  
  2679. Physical Storage Methods
  2680.  
  2681. In previous versions of HDF, each data element was required to
  2682. occupy one contiguous block of space in a single file. But,
  2683. beginning with HDF Version 3.2, a mechanism was added to support
  2684. different methods of physical storage of data elements. The new
  2685. mechanism is called the "extended tag."
  2686.  
  2687. Any of the NCSA standard tags can take advantage of the new
  2688. features of the extended tags. Extended tags are automatically
  2689. recognized by the library and interpreted according to a
  2690. description record. The description record is a complete data
  2691. element unto itself which identifies the type of extended element
  2692. and provides the relevant parameters for retrieval of that element.
  2693. Currently, there are two types of extended tags, both of which
  2694. offer alternate methods of physical storage: linked block elements
  2695. and external elements.
  2696.  
  2697. Linked Block Elements
  2698.  
  2699. Linked block elements provide a convenient way of adding data to
  2700. a pre-existing element. They consist of a series of blocks of data
  2701. chained together in a linked list (similar to the DD list). In
  2702. general, the data blocks are of a uniform size. However, the first
  2703. block is considered a special case and is allowed to have a
  2704. different size from the rest of the blocks.
  2705.  
  2706. The description record for a linked block element begins with the
  2707. constant EXT_LINKED, which identifies the linked block storage
  2708. method. It also contains information about the organization of the
  2709. linked block element as a whole. Figure 6.1 shows a diagram of a
  2710. description record for a linked block element.
  2711.  
  2712. *** INSERT FIGURE HERE ***
  2713.  
  2714. <extended tag>           any NCSA standard tag converted to an
  2715.                          extended tag (16-bit integer)
  2716. <ref no>                 reference number (16-bit integer)
  2717. EXT_LINKED               constant identifying this as a linked
  2718.                          block description record (32-bit integer)
  2719. <length>                 length of entire element (32-bit integer)
  2720. <first len>              length of the first data block (32-bit
  2721.                          integer)
  2722. <blk len>                length of successive data blocks (32-bit
  2723.                          integer)
  2724. <num blk>                number of blocks per block table (32-bit
  2725.                          integer)
  2726. <link ref>               reference number of first block table
  2727.                          (16-bit integer)
  2728.  
  2729. The <link ref> field of-the description record gives the reference
  2730. number of the first linked block table for the element. This table
  2731. is identified by the tag DFTAG_LINKED and contains <num blk>
  2732. entries. There may be any number of linked block tables chained
  2733. together to describe a linked block element. Figure 6.2 shows a
  2734. diagram of a linked block table.
  2735.  
  2736. *** INSERT FIGURE HERE ***
  2737.  
  2738. <link ref>               reference number for this block table
  2739.                          (16-bit integer)
  2740. <next ref>               reference number for next block table
  2741.                          (16-bit integer)
  2742. <blk ref n>              reference number for data block (16-bit
  2743.                          integer)
  2744.  
  2745. The <next ref> field contains the reference number of the next
  2746. linked block table. A value of zero (0) in this field indicates
  2747. that there are no additional linked block tables associated with
  2748. this linked block element.
  2749.  
  2750. The <blk ref n> fields of each linked block table contain reference
  2751. numbers for the individual data blocks that make up the data
  2752. portion of the linked block element. These data blocks are also
  2753. identified by the tag DFTAG_LINKED as shown in Figure 6.3. Although
  2754. it may seem ambiguous to use the same tag to refer to two different
  2755. objects, this ambiguity is alleviated by the context in which the
  2756. tags appear.
  2757.  
  2758. *** INSERT FIGURE HERE ***
  2759.  
  2760. <blk ref n>              reference number for this data block
  2761.                          (16-bit integer)
  2762. <data block>             block of actual data (size given by
  2763.                          <first len> or <blk len> from the
  2764.                          description record)
  2765.  
  2766. Linked block elements can be created using the function HLcreate(),
  2767. which is discussed in detail in the chapter "The NCSA HDF General
  2768. Purpose Interface."
  2769.  
  2770. External Elements
  2771.  
  2772. External elements allow the data portion of an HDF element to
  2773. reside in a separate file. The potential of external data elements
  2774. is largely unexplored in the HDF context, although other file
  2775. formats (most notably CDF) have used external data elements
  2776. apparently to great advantage.
  2777.  
  2778. Because there has been little discussion of external elements
  2779. within the HDF user community, the structure of these elements is
  2780. still not completely defined. Figure 6.4 shows a diagram of the
  2781. proposed structure for an external element.
  2782.  
  2783. *** INSERT FIGURE HERE ***
  2784.  
  2785.  
  2786. <extended tag>           any NCSA standard tag converted to
  2787.                          an extended tag (16-bit integer)
  2788. <re no>                  reference number (16-bit integer)
  2789. EXT_EXTERN               constant identifying this as an external
  2790.                          element description record (16-bit
  2791.                          integer)
  2792. <offset>                 location of the data within the external
  2793.                          file (32-bit integer)
  2794. <length>                 length in bytes of the data in the
  2795.                          external file (32-bit integer)
  2796. <filename>               non-null terminated ASCII string
  2797.                          containing the name of the external file
  2798.                          in which the data resides (any length)
  2799.  
  2800. The description record for an external element begins with the
  2801. constant EXT_EXTERN, which identifies the external storage method.
  2802. It also contains information  about how to find the element.
  2803.  
  2804. External elements can be created using the function HXcreate() ,
  2805. which is discussed in detail in the chapter "The NCSA HDF General
  2806. Purpose Interface."
  2807.  
  2808. Specifications of Supported Tags
  2809.  
  2810. The following pages contain the specifications of all the tags that
  2811. are officially supported as of HDF version 3.2. Each entry is to
  2812. be interpreted as follows:
  2813.  
  2814. * The word id capital letters on the left is the tag name.
  2815.  
  2816. * The three short lines at the beginning of each description
  2817.   uniquely identify the tag:
  2818.  
  2819.   The first line is the full name of the tag.
  2820.  
  2821.   The second line describes the type and (where possible) the
  2822.   amount of data in the corresponding data element. When the data
  2823.   element is a variable-sized data structure-such as text, a
  2824.   string, or a variable-sized array-the amount of data cannot be
  2825.   specified exactly. Where possible, a formula is given for
  2826.   estimating the amount of data. If the second line is "? bytes,
  2827.   it means that neither the size nor the structure of the data
  2828.   element can be specified.
  2829.  
  2830.   The third line gives the tag number in decimal and (hexadecimal).
  2831.  
  2832. * Next is a diagram showing, as nearly as possible, the structure
  2833.   of the tag and its associated data.
  2834.  
  2835. * Finally, a full specification of the tag is presented, including
  2836.   a description of the data element and a discussion of its
  2837.   intended use.
  2838.  
  2839. These listings are grouped approximately according to the roles
  2840. that the tags play under the headings Utility Tags, Annotation
  2841. Tags, Raster Image Tags, and so forth. These groupings imply a
  2842. general context for the use of each tag, but are not meant to
  2843. restrict the use of the tags to any particular context.
  2844.  
  2845. Please note that the subsection under the heading Obsolete Tags
  2846. contains the specifications for tags that have fallen out of use
  2847. with the continuing development of HDF. These tags are still
  2848. recognized by the HDF library, but it is not recommended that users
  2849. write out new objects using these tags, since some of them may
  2850. eventually be dropped from the HDF specification.
  2851.  
  2852. Utility Tags
  2853.  
  2854. DFTAG_NULL
  2855.  
  2856. No data
  2857. 0 bytes
  2858. 1  (0X0001)
  2859.  
  2860. *** INSERT FIGURE HERE ***
  2861.  
  2862. <ref no>  reference number (16-bit integer; always 0)
  2863.  
  2864. This tag is used for place holding and to fill empty portions of
  2865. the data description block. The length and offset fields (not
  2866. shown) of a NULL DD must be equal to zero.
  2867.  
  2868. DFTAG_VERSION
  2869.  
  2870. Library version number
  2871. 12 bytes plus the length of a string
  2872. 30 (0x001E)
  2873.  
  2874. *** INSERT FIGURE HERE ***
  2875.  
  2876. <ref no>  reference number (16-bit integer)
  2877. <major>   Major version number (32-bit integer)
  2878. <minor>   minor version number (32-bit integer)
  2879. <release> release number (32-bit integer)
  2880. <string>  non-null terminated ASCII string (any length)
  2881.  
  2882. The data portion of this tag gives the complete version number and
  2883. a descriptive string for the latest version of the HDF library to
  2884. write to the file.
  2885.  
  2886. DFTAG_NT
  2887.  
  2888. Number type
  2889. 4 bytes
  2890. 106 (0x006A)
  2891.  
  2892. *** INSERT FIGURE HERE ***
  2893.  
  2894. <ref no>  reference number (16-bit integer)
  2895. <version> version number of NT information (8-bit integer)
  2896. <type>    unsigned int, signed int, unsigned char, char, float,
  2897.           double (8-bit code)
  2898. <width>   number of bits (assumed all significant) (8-bit code)
  2899. <class>   a generic value, with different interpretations depending
  2900.           on type: floating-point, integer, or character (8-bit
  2901.           code)
  2902.  
  2903. Some possible :values that may be included for each of the three
  2904. types in the field CLASS are listed in Table 6.1.
  2905.  
  2906. Table 6.1      Number Type Values
  2907.  
  2908. Type      Possible Values
  2909.  
  2910. floats    DFNTF_NONE
  2911.           DFNTF_IEEE
  2912.           DFNTF_VAX
  2913.           DFNTF_CRAY
  2914.           DFNTF_PC
  2915.           DFNTF_CONVEX
  2916.  
  2917. ints      DFNTI_MBO
  2918.           DFNTI_IBO
  2919.           DFNTI-VBO
  2920.  
  2921. chars     ASCII
  2922.           EBCDIC, BYTE
  2923.  
  2924. The number type flag is used by any other element in the file to
  2925. indicate specifically what a numeric value looks like other tag
  2926. types should contain a reference number pointer to an DFTAG_NT
  2927. instead of containing their own number type definitions.
  2928.  
  2929. The version field allows expansion of the number type information,
  2930. in case some future number types cannot be described using the
  2931. fields currently defined. Successive versions of the DFTAG_NT may
  2932. be substantially different from the current definition, however,
  2933. backward compatibility will be maintained. The current DFTAG_NT.
  2934. version number is 1.
  2935.  
  2936. DFTAG_MT
  2937.  
  2938. Machine type
  2939. 0 bytes
  2940. 107 (0x006B)
  2941.  
  2942. *** INSERT FIGURE HERE ***
  2943.  
  2944. <double>  specifies method of encoding double precision floating
  2945.           point (4-bit code)
  2946. <float>   specifies method of encoding single precision floating
  2947.           point (4-bit code)
  2948. <int>     specifies method of encoding integers (4-bit code)
  2949. <char>    specifies method of encoding characters (4-bit code)
  2950.  
  2951. The DFTAG_MT specifies that all unconstrained or partially
  2952. constrained values in this HDF file are of the default type for
  2953. that hardware. When the DFTAG_MT is set to VAX, for example, all
  2954. integers will be assumed to be in VAX byte order unless
  2955. specifically defined otherwise with a DFTAG NT. Note that all of
  2956. the headers and many tags, the whole raster image set for example,
  2957. are defined with bit-wise precision and will not be overridden by
  2958. the DFTAG_MT setting.
  2959.  
  2960. For DRTAG_MT, the reference field itself is the encoding of the
  2961. DFTAG_MT information. The reference field is 16 bits, taken as four
  2962. groups of four bits, specifying the types for double, float, int
  2963. and char respectively. This allows 16 generic specifications for
  2964. each type.
  2965.  
  2966. To the user, these will be defined constants in the header file
  2967. hdf.h, specifying the proper descriptive numbers for Sun, VAX,
  2968. Cray, Convex, and other computer systems. If there is no DFTAG_MT
  2969. in a file, the application may assume that the data in the file has
  2970. been written on the local machine--assuming any portability
  2971. problems are taken care of by the user. For this reason, we
  2972. recommend that all HDF files contain a DFTAG_MT for maximum
  2973. portability.
  2974.  
  2975.  
  2976. Possible data encodings are shown in Table 6.2.
  2977.  
  2978. Table 6.2  Possible Machine Types
  2979.  
  2980. Type           Possible Encodings
  2981.  
  2982. double         IEEE64, VAX64, CRAY128
  2983. floats         IEEE32, VAX32, CRAY64
  2984. ints           VAX32, Intell6, Intel32, Motorola32, CRAY64
  2985. chars          ASCII, EBCDIC
  2986.  
  2987. New encodings can be added for each data type, as the need arises.
  2988.  
  2989. DFTAG_FID
  2990.  
  2991. File identifier
  2992. string
  2993. 100 (0x0064)
  2994.  
  2995. *** INSERT FIGURE HERE ***
  2996.  
  2997. <ref no>            reference number (16-bit integer)
  2998. <character string>  non-null terminated ASCII text (any length)
  2999.  
  3000. This tag points to a string which the user wants to associate with
  3001. this file. The string is not null terminated. The string is
  3002. intended to be a user-supplied title for the file.
  3003.  
  3004. DFTAG_FD
  3005.  
  3006. File description
  3007. text
  3008. 101 (0x0065)
  3009.  
  3010. *** INSERT FIGURE HERE ***
  3011.  
  3012. <ref no>       reference number (16-bit integer)
  3013. <text block>   non-null terminated ASCII text (any length)
  3014.  
  3015. This tag points to a block of text describing the overall file
  3016. contents. The text can be any length. The block is not null
  3017. terminated. The text is intended to be user-supplied comments about
  3018. the file.
  3019.  
  3020. DFTAG_TID
  3021.  
  3022. Tag identifier
  3023. string
  3024. 102 (0x0066)
  3025.  
  3026. *** INSERT FIGURE HERE ***
  3027.  
  3028. <tag>               tag number to which this tag refers (16-bit
  3029.                     integer)
  3030. <character string>  non-null terminated ASCII text (any length)
  3031.  
  3032. The data for this tag is a string that identifies the functionality
  3033. of the tag indicated in the space normally used for the reference
  3034. number. For example, the tag identifier for DFTAG_TID might point
  3035. to data that reads "tag identifier."
  3036.  
  3037. Many tags are identified in the HDF specification, so it is usually
  3038. unnecessary to include their identifiers in the HDF file. But with
  3039. user-defined tags or special-purpose tags, the only way for a human
  3040. reader to diagnose what kind of data is stored in a file is to read
  3041. tag identifiers. Use tag descriptions to define even more detail
  3042. about your user-defined tags.
  3043.  
  3044. Note that with this tag you may make use of the user-defined tags
  3045. to check for consistency. Although two persons may use the same
  3046. user-defined tag, they probably will not use the same tag
  3047. identifier.
  3048.  
  3049. DFTAG_TD
  3050.  
  3051. Tag description
  3052. text
  3053. 103 (0x0067)
  3054.  
  3055. *** INSERT FIGURE HERE ***
  3056.  
  3057. <tag>          tag number to which this tag refers (16-
  3058.                bit integer)
  3059. <text block>   non-null terminated ASCII text (any length)
  3060.  
  3061. The data for this tag is a text block which describes in relative
  3062. detail the functionality and format of the tag which is indicated
  3063. in the space normally occupied by the reference number. This tag
  3064. is mainly intended to be used with user-defined tags and provides
  3065. a medium for users to exchange files that include human-readable
  3066. descriptions of the data.
  3067.  
  3068. It is important to provide everything that a programmer might need
  3069. to know to read the data from your user-defined tag. At the
  3070. minimum, you should specify everything you would need to know in
  3071. order to retrieve your data at a later date if the original program
  3072. were lost.
  3073.  
  3074. DFTAG_DIL
  3075.  
  3076. Data identifier label
  3077. string
  3078. 104 (0x0068)
  3079.  
  3080. *** INSERT FIGURE HERE ***
  3081.  
  3082. <ref no>            reference number (16-bit integer)
  3083. <obj tag>           tag number of the data to which this label
  3084.                     applies (16-bit integer)
  3085. <obj ref no>        reference of the data to which this label
  3086.                     applies (16-bit integer)
  3087. <character string>  non-null terminated ASCII text (any length)
  3088.  
  3089. The data for this tag is a data identifier, made up of a tag and
  3090. reference number, followed by a string that the user wants to place
  3091. in the file. The purpose of this tag is to associate the string
  3092. with the data identifier as a label for whatever that data
  3093. identifier refers to in turn.
  3094.  
  3095. By including DFTAG_DILs, you can give a data object a label for
  3096. future reference. For example, DFTAG_DIL is often used to give
  3097. titles to images.
  3098.  
  3099. DFTAG_DIA
  3100.  
  3101. Data identifier annotation
  3102. text
  3103. 105 (0x0069)
  3104.  
  3105. *** INSERT FIGURE HERE ***
  3106.  
  3107. <ref no>       reference number (16-bit integer)
  3108. <obj tag>      tag number of the data to which this annotation
  3109.                applies (16-bit integer)
  3110. <obj ref no>   reference of the data to which this annotation
  3111.                applies (16-bit integer)
  3112. <text block>   non-null terminated ASCII text (any length)
  3113.  
  3114. The data for this tag is a data identifier, which is made up of a
  3115. tag and a reference number, followed by a text block that the user
  3116. wants to place in the file. Its purpose is to associate the text
  3117. block with the data identifier as an annotation for whatever that
  3118. data identifier points to in turn.
  3119.  
  3120. With DFTAG_DIA, any data object can have a lengthy, user-written
  3121. description of why that data is in the file. This can be used to
  3122. include user comments about images, datasets, source code, and so
  3123. forth.
  3124.  
  3125. Compression Tags
  3126.  
  3127. DFTAG_RLE
  3128.  
  3129. Run length encoded data
  3130. 0 bytes
  3131. 11 (0X000B)
  3132.  
  3133. *** INSERT FIGURE HERE ***
  3134.  
  3135. <ref no>       reference number (16-bit integer)
  3136.  
  3137. This tag is used in the compression field of a DFTAG_ID and other
  3138. places to indicate that an image or section of data is encoded with
  3139. a run-length encoding scheme. The RLE method used is byte-wise.
  3140. Each run is preceded by a count byte. The low seven bits of the
  3141. count byte indicate the number of bytes (n). The high bit of the
  3142. count byte indicates whether the next byte should be replicated n
  3143. times (high bit=1), or whether the next n bytes should be included
  3144. as is (high bit=0).
  3145.  
  3146. See also: DFTAG_ID (General Raster Image Tags)
  3147.           DFTAG_NDG (Scientific Dataset Tags)
  3148.  
  3149. DFTAG_IMC
  3150.  
  3151. IMCOMP compressed data
  3152. 0 bytes
  3153. 12 (0X000C)
  3154.  
  3155. *** INSERT FIGURE HERE ***
  3156.  
  3157. <ref no>       reference number (16-bit integer)
  3158.  
  3159. This tag is used in the ID compression field and other places to
  3160. indicate that an image or section of data is encoded with an IMCOMP
  3161. encoding scheme. This scheme is a 4:1 aerial averaging method which
  3162. is easy to decompress. It counts color frequencies in 4x4 squares
  3163. to optimize color sampling.
  3164.  
  3165. See also: DFTAG_ID (General Raster Image Tags)
  3166.           DFTAG_NDC (Scientific Dataset Tags)
  3167.  
  3168. DFTAG_JPEG
  3169.  
  3170. 24-bit JPEG compression information
  3171. ? bytes
  3172. 13 (0X000D)
  3173.  
  3174. *** INSERT FIGURE HERE ***
  3175.  
  3176. <ref no>       reference number (16-bit integer)
  3177.  
  3178. This tag points to header information for 24-bit JPEG compressed
  3179. images. The data in this tag is identical to the data stored in a
  3180. JFIF (JPEG File Interchange Format) file up to the Start-of-Frame
  3181. parameter (see the JFIF format document for further details). The
  3182. Start-of-Frame parameter and all further data for the JPEG image
  3183. is stored the in associated DFTAG_CI data element which is the
  3184. companion to the DFTAG_JPEG element.
  3185.  
  3186. DFTAG_GREYJPEG
  3187.  
  3188. 8-bit JPEG compression information
  3189. ? bytes
  3190. 14 (0X000E)
  3191.  
  3192. *** INSERT FIGURE HERE ***
  3193.  
  3194. <ref no>       reference number (16-bit integer)
  3195.  
  3196. This tag points to header information for 8-bit JPEG compressed
  3197. images. The data in this tag is identical to the data stored in a
  3198. JFIF (JPEG File Interchange Format) file up to the Start-of-Frame
  3199. parameter (see the JFIF format document for further details). The
  3200. Start-of-Frame parameter and all further data for the JPEG image
  3201. is stored the in associated DFTAG-CI data element which is the
  3202. companion to the DFTAG-JPEG element.
  3203.  
  3204. General Raster Image Tags
  3205.  
  3206. DFTAG_RIG
  3207.  
  3208. Raster image group
  3209. n*4 bytes (where n is the number of data objects in the group.)
  3210. 306 (0x0132)
  3211.  
  3212. *** INSERT FIGURE HERE ***
  3213.  
  3214. <ref no>        reference number (16-bit integer)
  3215. <tag n>         tag number for nth member of the group (16-bit
  3216.                 integer)
  3217. <ref n>         reference number for nth member of the group
  3218.                 (16-bit integer)
  3219.  
  3220. The raster image group (RIG) data is a list of data identifiers
  3221. (tag/ref) that describe a raster image. All of the members of the
  3222. group are required in order to display the image correctly.
  3223. Application programs that deal with RIGs should read all the
  3224. elements of a RIG and process those identifiers which it can
  3225. display correctly. Even if the application cannot process all of
  3226. the tags, the tags that it can process will be usable.
  3227.  
  3228. Tag types that may appear in a RIG are listed in Table 6.3.
  3229.  
  3230. Table 6.3  Possible Tag Types in an RIG
  3231.  
  3232. Tag            Description
  3233.  
  3234. DFTAG_ID       Image dimension
  3235. DFTAG_RI       raster image
  3236. DFTAG_XYP      X-Y position
  3237. DFTAG_LD       LUT dimension
  3238. DFTAG_LUT      color lookup table
  3239. DFTAG_MD       matte channel dimension
  3240. DFTAG_MA       matte channel
  3241. DFTAG_CCN      color correction
  3242. DFTAG_CFM      color format
  3243. DFTAG_AR       aspect ratio
  3244.  
  3245. Example
  3246.  
  3247. ID, RI, LD, LUT
  3248.  
  3249. An image dimension record, the raster image, an LUT dimension and
  3250. the LUT go together. The application reads the image dimensions,
  3251. then reads the image with those dimensions. It also reads the
  3252. lookup table according to its dimensions and displays the
  3253. corresponding image.
  3254.  
  3255. DFTAG_ID,           DFTAG_LD,           DFTAG_MD
  3256.  
  3257. Image dimension     LUT dimension       Matte dimension
  3258. 20 bytes            20 bytes            20 bytes
  3259. 300 (0x012C)        307 (0x0133)        308 (0x0134)
  3260.  
  3261. *** INSERT FIGURE HERE ***
  3262.  
  3263. <ref no>       reference number (16-bit integer)
  3264. <x dim>        length of x (horizontal) dimension (32-bit integer)
  3265. <y dim>        length of y (vertical) dimension (32-bit integer)
  3266. <NT ref>       reference number of number type information for
  3267.                associated object
  3268. <elements>     number of elements that comprise one entry (16-bit
  3269.                integer)
  3270. <interlace>    defines type of interlacing used (16-bit integer)
  3271. <comp tag>     tag which tells the type of compression used and any
  3272.                associated parameters (16-bit integer)
  3273. <comp ref>     reference number of compression tag (16-bit integer)
  3274.  
  3275. The three dimension records have exactly the same format. They
  3276. define the dimensions of the 2D array to which they refer. The
  3277. diagram above pictures a DFTAG_ID for illustration. A DFTAG_ID
  3278. specifies the dimensions of a DFTAG_RI, DFTAG_LD specifies the
  3279. dimensions of a DFTAG_LUT, and DFTAG_HD specifies the dimensions
  3280. of a DRTAG_MA.
  3281.  
  3282. For example, a 512x256 row-wise 24-bit raster image with each pixel
  3283. stored as RGB bytes would have the following values:
  3284.  
  3285. <x dim>:       512
  3286. <y dim>:       256
  3287. <NT ref>       UINT8
  3288. <elements>     3 (3 elements per pixel: e.g., R,G and B)
  3289. <interlace>    0 (RGB values not separated)
  3290. <comp tag>     0 (no compression is used)
  3291.  
  3292. DFTAG_RI
  3293.  
  3294. Raster image
  3295. xdim*ydim*elements*NTsize bytes (xdim, ydim, elements, and NTsize
  3296. are given by the corresponding DFTAG_ID)
  3297.  
  3298. 302 (0x012E)
  3299.  
  3300. *** INSERT FIGURE HERE ***
  3301.  
  3302. <ref no>            reference number (16-bit integer)
  3303.  
  3304. This tag points to raster image data. It is stored in row-major
  3305. order and must be interpreted as specified in a DFTAG_ID:
  3306.  
  3307. <interlace>=0  means the components of each pixel are together.
  3308. <interlace>=1  means color elements are grouped by scan lines.
  3309. <interlace>=2  means color elements are grouped by planes.
  3310.  
  3311. DFTAG_LUT
  3312.  
  3313. Lookup table
  3314. xdim*ydim*elements*NTsize bytes (xdim, ydim, elements, and NTsize
  3315. are given by the corresponding DFTAG_ID)
  3316.  
  3317. 301 (0x012D)
  3318.  
  3319. *** INSERT FIGURE HERE ***
  3320.  
  3321. <ref no>       reference number (16-bit integer)
  3322. <Pn m>         Mth value of parameter n (size is given by the
  3323.                DFTAG_NT in the corresponding DFTAG_LD)
  3324.  
  3325. The DFTAG-LUT, sometimes called a palette, is used by many kinds
  3326. of hardware to assign colors to data values. When a raster image
  3327. consists of data values which are going to be interpreted through
  3328. hardware with a LUT capability, the DFTAG_LUT should be loaded
  3329. along with the image.
  3330.  
  3331. The most common lookup table is the RGB lookup table which will
  3332. have X dimension-256 and Y dimension-1 with three elements per
  3333. entry, one each for red, green, and blue. The interlace will be
  3334. either 0, where the LUT values are given RGB, RGB, RGB ..., or 1,
  3335. where the LUT values are given as 256 reds, 256 greens, 256 blues.
  3336.  
  3337. DFTAG_MA
  3338.  
  3339. matte channel
  3340. xdim*ydim*elements*NTsize bytes (xdim, ydim, elements, and NTsize
  3341. are given by the corresponding DFTAG_ID)
  3342.  
  3343. 309 (0x0135)
  3344.  
  3345. *** INSERT FIGURE HERE ***
  3346.  
  3347. <ref no>       reference number (16-bit integer)
  3348.  
  3349. The DFTAG_MA contains transparency data which can be used to
  3350. facilitate the overlaying of images. The data consist of a
  3351. two-dimensional array of unsigned 8-bit integers ranging from 0 to
  3352. 255. Each point in a DFTAG-MA indicates the transparency of the
  3353. corresponding point in a raster image of the same dimensions. A
  3354. value of 0 indicates that the data at that point is to be
  3355. considered totally transparent, while a value of 255 indicates that
  3356. the data at that point is totally opaque. It is assumed that a
  3357. linear scale applies to the transparency values, but users may opt
  3358. to interpret the data in any way they wish.
  3359.  
  3360. DFTAG_CCN
  3361.  
  3362. Color correction
  3363. 52 bytes (usually)
  3364. 310 (0x0136)
  3365.  
  3366. *** INSERT FIGURE HERE ***
  3367.  
  3368. <ref no>       reference number (16-bit integer)
  3369. <gamma>        gamma parameter (32-bit IEEE float)
  3370. <red x/y/z>    red x/y/z correction factors (32-bit IEEE floats)
  3371. <green x/y/z>  green x/y/z correction factors (32-bit IEEE floats)
  3372. <blue x/y/z>   blue x/y/z correction factors (32-bit IEEE floats)
  3373. <white x/y/z>  white x/y/z correction factors (32-bit IEEE floats)
  3374.  
  3375. Color correction specifies the Gamma correction for the image and
  3376. color primaries for the generation of the image.
  3377.  
  3378. DFTAG_CFM
  3379.  
  3380. Color format
  3381. string
  3382. 311 (0x0137)
  3383.  
  3384. *** INSERT FIGURE HERE ***
  3385.  
  3386. <ref no>            reference number (16-bit integer)
  3387. <character string>  non-null terminated ASCII string (any length)
  3388.  
  3389. The color format is a clue to how each element of each pixel in a
  3390. raster image can be interpreted. It is defined to be a string which
  3391. is in all caps, and is one of the values shown in Table 6.4.
  3392.  
  3393. Table 6.4  Color Format String Values
  3394.  
  3395. String         Description
  3396.  
  3397. VALUE          pseudo-color, or just a value associated with the pixel
  3398. RGB            red, green, blue model
  3399. XYZ           color-space model
  3400. HSV            hue, saturation, value model
  3401. HSI            hue, saturation, intensity
  3402. SPECTRAL       spectral sampling method
  3403.  
  3404. DFTAG_AR
  3405.  
  3406. Aspect ratio
  3407. 4 bytes
  3408. 312 (0x0138)
  3409.  
  3410. *** INSERT FIGURE HERE ***
  3411.  
  3412. <ref no>       reference number (16-bit integer)
  3413. <ratio>        ratio of width to height (32-bit IEEE float)
  3414.  
  3415. The data for this tag is the visual aspect ratio for this image.
  3416. The image should be visually correct if displayed on a screen with
  3417. this aspect ratio. The data consists of one floating-point number
  3418. which represents width divided by height. An aspect ratio of 1.0
  3419. indicates a display with perfectly square pixels; 1.33 is a
  3420. standard aspect ratio used by many monitors.
  3421.  
  3422. Composite Image Tags
  3423.  
  3424. DFTAG_DRAW
  3425.  
  3426. Draw
  3427. n*4 bytes (where n is the number of data objects that comprise the
  3428. composite image.)
  3429. 400 (0x0190)
  3430.  
  3431. *** INSERT FIGURE HERE ***
  3432.  
  3433. <ref no>       reference number (16-bit integer)
  3434. <tag n>        tag number of the nth member of the draw list
  3435.                (16-bit integer)
  3436. <ref n>        reference number of the nth member of the draw list
  3437.                (16-bit integer)
  3438.  
  3439. The data for this tag is a list of data identifiers (tag/ref pairs)
  3440. which define a composite image. Each member of the DRTAG_DRAW data
  3441. should be displayed, in order, on the screen. This can be used to
  3442. indicate several RIGs which should be displayed simultaneously, or
  3443. even include vector overlays, like DRTAG_T14, which should be
  3444. placed on top of a RIG.
  3445.  
  3446. Some of the elements in a DRAW list may be instructions about how
  3447. images are to be composited (XOR, source put, anti-aliasing, etc.).
  3448. These are defined as individual tags.
  3449.  
  3450. DFTAG_XYP
  3451.  
  3452. XY position
  3453. 8 bytes
  3454. 500 (0x01F4)
  3455.  
  3456. *** INSERT FIGURE HERE ***
  3457.  
  3458. <ref no>       reference number (16-bit integer)
  3459. <x>            x-coordinate (32-bit integer)
  3460. <Y>            y-coordinate (32-bit integer)
  3461.  
  3462. A DFTAG_XYP is used in composites-and other groups to indicate an
  3463. XY position on the screen. For this, (0,0) is the lower left, X is
  3464. the number of pixels to the right along the horizontal axis and Y
  3465. is the number of pixels on the vertical axis. The X and Y pixel
  3466. dimensions are given as two 32-bit integers.
  3467.  
  3468. For example, if DFTAG_XYP is present inside a DFTAG_RIG, the
  3469. DFTAG_XYP refers to the position of the lower left corner of the
  3470. raster image on the screen.
  3471.  
  3472. See also:      DFTAG_DRAW (this section)
  3473.  
  3474. Vector Image Tags
  3475.  
  3476. DFTAG_T14
  3477.  
  3478. Tektronix 4014
  3479. ? bytes
  3480. 602 (0x25A)
  3481.  
  3482. *** INSERT FIGURE HERE ***
  3483.  
  3484. <ref no>       reference number (16-bit integer)
  3485.  
  3486. This tag points to a Tektronix 4014 data stream. The bytes in the
  3487. data field, when read and sent to a Tektronix 4014 terminal, will
  3488. display a vector image. Only the lower seven bits of each byte are
  3489. significant. There are no record markings or non-Tektronix codes
  3490. in the data.
  3491.  
  3492. DFTAG_T105
  3493.  
  3494. Tektronix 4105
  3495. ? bytes
  3496. 603 (0x25B)
  3497.  
  3498. *** INSERT FIGURE HERE ***
  3499.  
  3500. <ref no>       reference number (16-bit integer)
  3501.  
  3502. This tag points to a Tektronix 4105 data stream. The bytes in the
  3503. data field, when read and sent to a Tektronix 4105 terminal, will
  3504. be displayed as a vector image. Only the lower seven bits of each
  3505. byte are significant. Some terminal emulators will not correctly
  3506. interpret every feature of the Tektronix 4105 terminal, so you may
  3507. wish to use only a subset of the possible Tektronix 4105 vector
  3508. commands.
  3509.  
  3510. Scientific Dataset Tags
  3511.  
  3512. DFTAG_NDG
  3513.  
  3514. Numeric data group
  3515. n*4 bytes (where n is the number of data objects in the group.)
  3516. 720 (0x02D0)
  3517.  
  3518. *** INSERT FIGURE HERE ***
  3519.  
  3520. <ref no>       reference number (16-bit integer)
  3521. <tag n>        tag number of nth member of the group (16-bit
  3522.                integer)
  3523. <ref n>        reference number of nth member of the group (16-bit
  3524.                integer)
  3525.  
  3526. The numeric data group (NDG) data is a list of data identifiers
  3527. (tag/ref pairs) that describe a scientific dataset. It supercedes
  3528. the old DFTAG_SDG, which has been obsoleted as of version 3.2 of
  3529. the HDF library. A more complete explanation of the relationship
  3530. between DFTAG_NDG and DFTAG_SDG can be found in the chapter
  3531. entitled "Sets and Groups."
  3532.  
  3533. All of the members of the group provide information for correctly
  3534. interpreting and displaying the data. Application programs that
  3535. deal with NDGs should read all of the elements of a NDG and process
  3536. those identifiers which it can use. Even if an application cannot
  3537. process all of the tags, the tags that it can understand will be
  3538. usable.
  3539.  
  3540. Tag types that may appear in a DFTAG_NDG are listed in Table 6.5.
  3541.  
  3542. Table 6.5  Possible Tag Types in an NDG
  3543.  
  3544. Tag            Description
  3545.  
  3546. DFTAG_SDD      scientific data dimension record (rank and dimensions)
  3547. DFTAG_SD       scientific data
  3548. DFTAG_SDS      scales
  3549. DFTAG_SDL      labels
  3550. DFTAG_SDU      units
  3551. DFTAG_SDF      formats
  3552. DFTAG_SDM      maximum and minimum values
  3553. DFTAG_SDC      coordinate system
  3554. DFTAC_CAL      calibration information
  3555. DFTAG_FV       fill value
  3556. DFTAG_LUT      color lookup table
  3557. DFTAG_LD       lookup table dimension record
  3558. DFTAG_SDLNK    link to old-style DFTAG_SDG (See Sets and Groups)
  3559.  
  3560. Example
  3561.  
  3562. DFTAG_SDD, DRTAG_SD, DRTAG_SDM
  3563. A dimension record, the scientific data, and the maximum and
  3564. minimum values of the data go together. The application reads the
  3565. rank and dimensions from the dimension record, then reads the data
  3566. array with those dimensions. If it needs maximum and minimum, it
  3567. also reads them.
  3568.  
  3569. See also: Sets and Groups
  3570.  
  3571. DFTAG_SDD
  3572.  
  3573. Scientific data dimension record
  3574. 6 + 8*rank bytes
  3575. 701 (0x02BD)
  3576.  
  3577. *** INSERT FIGURE HERE ***
  3578.  
  3579. <ref no>            reference number (16-bit integer)
  3580. <rank>              number of dimensions (16-bit integer)
  3581. <dim n>             number of values along the nth dimension
  3582.                     (32-bit integer)
  3583. <data NT ref>       reference number of DFTAG_NT for data
  3584.                     (16-bit integer)
  3585. <scale NT ref n>    reference number for DFTAG-NT for the
  3586.                     scale for the nth dimension (16-bit
  3587.                     integer)
  3588.  
  3589. This record defines the rank and dimensions of the array in the
  3590. scientific dataset. For example, a DFTAG_SDD for a 500X600X3 array
  3591. of floating-point numbers would have the following values and
  3592. components.
  3593.  
  3594. Rank: 3
  3595. Dimensions: 500, 600, and 3.
  3596. One data NT
  3597. Three scale NTs
  3598.  
  3599. DFTAG_SD
  3600.  
  3601. Scientific data
  3602. NTsize*x*y*z* ... bytes (where NTsize is the size of the data NT
  3603. given by the corresponding DFTAG_SDD and x, y, z, etc. are the
  3604. dimension sizes)
  3605. 702 (0x02BE)
  3606.  
  3607. *** INSERT FIGURE HERE ***
  3608.  
  3609. <ref no>       reference number (16-bit integer)
  3610.  
  3611. This tag points to an array of scientific data. The type of the
  3612. data may be specified by an DFTAG_NT included with the SDG. If
  3613. there is no DFTAG_NT, the type of the data is floating-point in
  3614. standard IEEE 32-bit format. The rank and dimensions must be stored
  3615. as specified in the corresponding DFTAG_SDD. The diagram above
  3616. shows a three-dimensional data array.
  3617.  
  3618. DFTAG_SDS
  3619.  
  3620. Scientific data scales
  3621. rank + NTsizeO*x + NTsize1*y +NTsize2*z +... bytes (where rank is
  3622. the number of dimensions, x, y, z, etc. are the dimension sizes,
  3623. and NTsize# are the sizes of each scale NT from the corresponding
  3624. DFTAG_SDD.)
  3625. 703 (0x02BF)
  3626.  
  3627. *** INSERT FIGURE HERE ***
  3628.  
  3629. <ref no>       reference number (16-bit integer)
  3630. <is n>         tells whether a scale exists for the nth dimension
  3631.                (8-bit integer; 0 or 1)
  3632. <scale n>      list of scale values for the nth dimension (type is
  3633.                given by corresponding DFTAG_SDD)
  3634.  
  3635. This tag points to the scales for the dataset. The first n bytes
  3636. indicate whether there is a scale for the corresponding dimension
  3637. (1=yes, 0=no). This is followed by the scale values for each
  3638. dimension. The scale consists of a simple series of values, where
  3639. the number of values and their types are given by the corresponding
  3640. DFTAG_SDD.
  3641.  
  3642. DFTAG_SDL
  3643.  
  3644. Scientific data labels
  3645. ? bytes
  3646. 704 (0x02C0)
  3647.  
  3648. *** INSERT FIGURE HERE ***
  3649.  
  3650. <ref no>       reference number (16-bit integer)
  3651. <label n>      null terminated ASCII string (any length)
  3652.  
  3653. This tag points to a list of labels for the data and each dimension
  3654. of the dataset. Each label is a string terminated by a null byte
  3655. (0).
  3656.  
  3657.  
  3658. DFTAG_SDU
  3659.  
  3660. scientific data units
  3661. ? bytes
  3662. 705 (0x02C1)
  3663.  
  3664. *** INSERT FIGURE HERE ***
  3665.  
  3666. <ref no>       reference number (16-bit integer)
  3667. <unit n>       null terminated ASCII string (any length)
  3668.  
  3669. This tag points to a list of strings specifying the units for the
  3670. data and each dimension of the dataset. Each unit's string is
  3671. terminated by a null byte (0).
  3672.  
  3673. DFTAG_SDF
  3674.  
  3675. Scientific data format
  3676. ? bytes
  3677. 706 (0x02C2)
  3678.  
  3679. *** INSERT FIGURE HERE ***
  3680.  
  3681. <ref no>       reference number (16-bit integer)
  3682. <format n>     null terminated ASCII string (any length)
  3683.  
  3684. This tag points to a list of strings specifying an output format
  3685. for the data and each dimension of the dataset. Each format string
  3686. is terminated by a null byte (0).
  3687.  
  3688. DFTAG_SDM
  3689.  
  3690. Scientific data max/min
  3691. 8 bytes
  3692. 707 (0x02C3)
  3693.  
  3694. *** INSERT FIGURE HERE ***
  3695.  
  3696. <ref no>       reference number (16-bit integer)
  3697. <max>          maximum value (type is given by the data NT in the
  3698.                corresponding DFTAG_SDD)
  3699. <min>          minimum value (type is given by the data NT in the
  3700.                corresponding DFTAG_SDD)
  3701.  
  3702. This record contains the maximum and minimum data values in the
  3703. dataset. The type of <max> and <min> are given by the data NT of
  3704. the corresponding DFTAG_SDD.
  3705.  
  3706. DFTAG_SDC
  3707.  
  3708. Scientific data coordinates
  3709. ? bytes
  3710. 708 (0x02C4)
  3711.  
  3712. *** INSERT FIGURE HERE ***
  3713.  
  3714. <ref no>       reference number (16-bit integer)
  3715. <string>       null terminated ASCII string (any length)
  3716.  
  3717. This tag points to a string specifying the coordinate system for
  3718. the dataset. The string is terminated by a null byte.
  3719.  
  3720. DFTAG_SDLNK
  3721.  
  3722. Scientific dataset link
  3723. 8 bytes
  3724. 710 (0x02C6)
  3725.  
  3726. *** INSERT FIGURE HERE ***
  3727.  
  3728. <ref no>       reference number (16-bit integer)
  3729. DFTAG_NDG      NDG tag (16-bit integer)
  3730. <NDG ref>      reference number of NDG (16-bit integer)
  3731. DFTAG_SDG      SDG tag (16-bit integer)
  3732. <SDG ref>      reference number of SDG (16-bit integer)
  3733.  
  3734. The purpose of this tag is to link together an old-style DFTAG_SDG
  3735. and a DFTAG_NDG in cases where the NDG contains 32-bit floating
  3736. point data and is, therefore, equivalent to an old SDG. A complete
  3737. description of the use of this tag can be found in the chapter
  3738. entitled "Sets and Groups"
  3739.  
  3740. See also: Sets and Groups
  3741.  
  3742. DFTAG_CAL
  3743.  
  3744. Calibration information
  3745. 36 bytes
  3746. 731 (0x02DB)
  3747.  
  3748. *** INSERT FIGURE HERE ***
  3749.  
  3750. <ref no>       reference number (16-bit integer)
  3751. <cal>          calibration factor (64-bit IEEE float)
  3752. <cal err>      error in calibration factor (64-bit IEEE float)
  3753. <off>          calibration offset (64-bit IEEE float)
  3754. <off err>      error in calibration offset (64-bit IEEE float)
  3755. <data type>    constant representing the effective data type of the
  3756.                calibrated data (32-bit integer)
  3757.  
  3758. This tag points to a calibration record for the associated
  3759. DFTAG_SD. The data can be calibrated by first multiplying by the
  3760. <cal> factor, then adding the <off> value. Also included in the
  3761. record are errors for the calibration factor and offset and a
  3762. constant indicating the effective data type of the calibrated data.
  3763. Possible values of <data type> are shown in Table 6.6.
  3764.  
  3765. Table 6.6  Possible calibrated data types
  3766.  
  3767. Data Type      Description
  3768.  
  3769. INT8           signed 8-bit integer
  3770. UINT8          unsigned 8-bit integer
  3771. INT16          signed 16-bit integer
  3772. UINT16         unsigned 16-bit integer
  3773. INT32          signed 32-bit integer
  3774. UINT32         unsigned 32-bit integer
  3775. FLOAT32        32-bit float
  3776. FLOAT64        64-bit float
  3777.  
  3778. DFTAG_FV
  3779.  
  3780. Fill value
  3781. ? bytes (size given by size of data NT in corresponding DFTAG_SDD)
  3782. 732 (0x02DC)
  3783.  
  3784. *** INSERT FIGURE HERE ***
  3785.  
  3786. <ref no>       reference number (16-bit integer)
  3787. <fill value>   value representing unset data in the corresponding
  3788.                DFTAG_SD (size given by size of data NT in
  3789.                corresponding DFTAG_SDD)
  3790.  
  3791. This tag points to a value which has been used to indicate unset
  3792. values in the associated DFTAG_SD. The number type of the value
  3793. (and, therefore, its size) is given in the corresponding DFTAG_SDD.
  3794.  
  3795. Vset DFTAG_VG
  3796.  
  3797. Vgroup
  3798. 14 + 4*nelt + namelen + classlen bytes (where nelt, namelen, and
  3799. classlen are given below)
  3800. 1965 (0x07AD)
  3801.  
  3802. *** INSERT FIGURE HERE ***
  3803.  
  3804. <ref no>       reference number (16-bit integer)
  3805. <nelt>         number of elements in the vgroup (16-bit integer)
  3806. <tag n>        tag of the nth member of the vgroup (16-bit integer)
  3807. <ref n>        reference number of the nth member of the vgroup
  3808.                (16-bit integer)
  3809. <namelen>      length of the name field (16-bit integer)
  3810. <name>         non-null terminated ASCII string (length given by
  3811.                <namelen>)
  3812. <classlen>     length of the class field (16-bit integer)
  3813. <class>        non-null terminated ASCII string (length given by
  3814.                <classlen>)
  3815. <extag>        extension tag (16-bit integer)
  3816. <exref>        extension reference number (16-bit integer)
  3817. <version>      version number of DFTAG_VG information (16-bit
  3818.                integer)
  3819. <more>         unused (2 zero bytes)
  3820.  
  3821. The DFTAG_VG provides a general-purpose grouping structure which
  3822. can be used to impose a hierarchical structure on the tags in the
  3823. group. Any HDF tag may be incorporated into a vgroup (including
  3824. other DFTAG_VGS).
  3825.  
  3826. For more information about Vsets, see the chapter entitled "HDF
  3827. Vsets"
  3828.  
  3829. DFTAG_VH
  3830.  
  3831. Vdata description
  3832. 22 + 10*nfields + Sfldnmlen n + namelen + classlen bytes (where
  3833. nfields, fldnmlen n, namelen, and classlen are given below)
  3834. 1962 (0x07AA)
  3835.  
  3836. *** INSERT FIGURE HERE ***
  3837.  
  3838. <ref no>       reference number (16-bit integer)
  3839. <interlace>    constant indicating interlace scheme used (16-bit
  3840.                integer)
  3841. <nvert>        number of entries in vdata (32-bit integer)
  3842. <ivsize>       size of one vdata entry (16-bit integer)
  3843. <nfields>      number of fields per entry in the vdata (16-bit
  3844.                integer)
  3845. <type n>       constant indicating the data type of the nth field
  3846.                of the vdata (16-bit integer)
  3847. <isize n>      size in bytes of the nth field of the vdata (16-bit
  3848.                integer)
  3849. <offset n>     offset of the nth field within the vdata (16-bit
  3850.                integer)
  3851. <order n>      ??? of the nth field of the vdata (16-bit integer)
  3852. <fldnmlen n>   length of the nth field name string (16-bit integer)
  3853. <fldnm n>      non-null terminated ASCII string (length given by
  3854.                corresponding <fldnmlen>)
  3855. <namelen>      length of the name field (16-bit integer)
  3856. <name>         non-null terminated ASCII string (length given by
  3857.                <namelen>)
  3858. <classlen>     length of the class field (16-bit integer)
  3859. <class>        non-null terminated ASCII string (length given by
  3860.                <classlen>)
  3861. <extag>        extension tag (16-bit integer)
  3862. <exref>        extension reference number (16-bit integer)
  3863. <version>      version number of DFTAG_VH information (16-bit
  3864.                integer)
  3865. <more>         unused (2 zero bytes)
  3866.  
  3867. DFTAG_VE provides all the information necessary to process a
  3868. DFTAG_VS.
  3869.  
  3870. For more information on Vsets, see the chapter entitled "HDF
  3871. Vsets."
  3872.  
  3873. See also: DFTAG_VS (this section)
  3874.  
  3875. DFTAG_VS
  3876.  
  3877. Vdata
  3878. nvert * Sisize n bytes (where nvert, and isize n are given by the
  3879. corresponding DFTAG_VH)
  3880. 1963 (0x07AB)
  3881.  
  3882. *** INSERT FIGURE HERE ***
  3883.  
  3884. <ref no>       reference number (16-bit integer)
  3885. <vdata>        data block interpreted according to the
  3886.                corresponding DFTAG_VH (nvert * Sisize n bytes,
  3887.                where nvert, and isize are given by the
  3888.                corresponding DFTAG_VH)
  3889.  
  3890. DFTAG_VS contains a block of data which is to be interpreted
  3891. according to the information in the corresponding DFTAG_VR.
  3892.  
  3893. For more information on Vsets, see the chapter entitled "HDF
  3894. Vsets."
  3895.  
  3896. See also: DFTAG_VE (this section)
  3897.  
  3898. Obsolete Tags
  3899.  
  3900. DFTAG_ID8
  3901.  
  3902. Image dimension-8
  3903. 4 bytes
  3904. 200 (0x00C8)
  3905.  
  3906. *** INSERT FIGURE HERE ***
  3907.  
  3908. <ref no>       reference number (16-bit integer)
  3909. <x dim>        length of x dimension (16-bit integer)
  3910. <y dim>        length of y dimension (16-bit integer)
  3911.  
  3912. The data for this tag consists of two 16-bit integers representing
  3913. the width and height of an 8-bit raster image in bytes.
  3914.  
  3915. This tag has been superceded by DFTAG_ID.
  3916.  
  3917. DFTAG_IP8
  3918.  
  3919. Image palette-8
  3920. 768 bytes
  3921. 201 (0x00C9)
  3922.  
  3923. *** INSERT FIGURE HERE ***
  3924.  
  3925. <ref no>       reference number (16-bit integer)
  3926. table entries  256 triples of 8-bit integers.
  3927.  
  3928. The data for this tag can be thought of as a table of 256 entries,
  3929. each containing one value for red, green, and blue. The first
  3930. triple is palette entry 0 and the last is palette entry 255.
  3931.  
  3932. This tag has been superceded by DFTAG_LUT.
  3933.  
  3934. DFTAG_RI8
  3935.  
  3936. Raster image-8
  3937. xdim*ydim bytes (where xdim and ydim are the dimensions given by
  3938. the corresponding DFTAG_ID8.)
  3939. 202 (0X00CA)
  3940.  
  3941. *** INSERT FIGURE HERE ***
  3942.  
  3943. <ref no>       reference number (16-bit integer)
  3944. image data     2-d array of 8-bit integers
  3945.  
  3946. The data for this tag is a row-wise representation of the
  3947. elementary 8-bit image data. The data is stored width-first (hence
  3948. row-wise) and is 8 bits per pixel. The first byte of data
  3949. represents the pixel in the upper-left hand corner of the image.
  3950.  
  3951. This tag has been superceded by DFTAG_RI.
  3952.  
  3953. DFTAG_CI8
  3954.  
  3955. Compressed image-8
  3956. ? bytes
  3957. 203 (0X00CB)
  3958.  
  3959. *** INSERT FIGURE HERE ***
  3960.  
  3961. <ref no>            reference number (16-bit integer)
  3962. <compressed image>  series of run-length encoded bytes
  3963.  
  3964. The data for this tag is a row-wise representation of the
  3965. elementary 8-bit image data. Each row is compressed using the
  3966. following run-length encoding where n is the lower seven bits of
  3967. the byte. The high bit represents whether the following n character
  3968. will be reproduced exactly (high bit-0) or whether the following
  3969. character will be reproduced n times (high bit=1) . Since DFTAG_CI8
  3970. and DFTAG_Rl8 are basically interchangeable, it is suggested that
  3971. you not have a DFTAG_CI8 and a DFTAG_RI8 that have the same
  3972. reference number.
  3973.  
  3974. This tag has been superceded by DFTAG_RLE.
  3975.  
  3976. DFTAG_II8
  3977.  
  3978. IMCOMP image-8
  3979. ? bytes
  3980. 204 (0X00CC)
  3981.  
  3982. *** INSERT FIGURE HERE ***
  3983.  
  3984. The data for this tag is a 4:1 compressed 8-bit image, using the
  3985. IMCOMP compression scheme.
  3986.  
  3987. This tag has been superceded by DFTAG_IMC.
  3988.  
  3989. DFTAG_SDG
  3990.  
  3991. Scientific data group
  3992. n*4 bytes (where n is the number of data objects in the group.)
  3993. 700 (0x02BC)
  3994.  
  3995. *** INSERT FIGURE HERE ***
  3996.  
  3997. <ref no>       reference number (16-bit integer)
  3998. <tag n>        tag number of nth member of the group (16-bit
  3999.                integer)
  4000. <ref n>        reference number of nth member of the group (16-bit
  4001.                integer)
  4002.  
  4003. The scientific data group (SDG) data is a list of data identifiers
  4004. (tag/ref pairs) that describe a scientific dataset. All of the
  4005. members of the group provide information for correctly interpreting
  4006. and displaying the data. Application programs that deal with SDGs
  4007. should read all of the elements of a SDG and process those
  4008. identifiers which it can use. Even if an application cannot process
  4009. all of the tags, the tags that it can understand will be usable.
  4010.  
  4011. Tag types that may appear in a DFTAG-SDG are listed in Table 6.7.
  4012.  
  4013. Table 6.7  Possible Tag Types in an SDG
  4014.  
  4015. Tag            Description
  4016.  
  4017. DFTAG_SDD      scientific data dimension record (rank and dimensions)
  4018. DFTAG_SD       scientific data
  4019. DFTAG_SDS      scales
  4020. DFTAG_SDL      labels
  4021. DFTAG_SDU      units
  4022. DFTAG_SDF      formats
  4023. DFTAG_SDM      maximum and minimum values
  4024. DFTAG_SDC      coordinate system
  4025. DFTAG_SDT      transposition (obsolete)
  4026. DFTAG_SDLNK    link to new DFTAG_NDG (see Sets and Groups)
  4027.  
  4028. Example
  4029.  
  4030. DFTAG_SDD, DFTAG_SD, DFTAG_SDM
  4031.  
  4032. A dimension record, the scientific data, and the maximum and
  4033. minimum values of the data go together. The application reads the
  4034. rank and dimensions from the dimension record, then reads the data
  4035. array with those dimensions. If it needs maximum and minimum, it
  4036. also reads them.
  4037.  
  4038. This tag has been superceded by DFTAG_NDG.
  4039.  
  4040. See also: Sets and Groups
  4041.  
  4042. DFTAG_SDT
  4043.  
  4044. Scientific data transpose
  4045. 0 bytes
  4046. 709 (0x02C5)
  4047.  
  4048. *** INSERT FIGURE HERE ***
  4049.  
  4050. <ref no>       reference number (16-bit integer)
  4051.  
  4052. The presence of this tag in a group indicates that the data pointed
  4053. to by the corresponding DFTAG_SD is in column-major order, instead
  4054. of the default row-major order. No data is associated with this
  4055. tag.
  4056.  
  4057. This tag will no longer be written by the HDF library, but if it
  4058. is encountered in an old file it will be interpreted as originally
  4059. intended.
  4060.  
  4061.  
  4062. Chapter 7 Making HDF Portable
  4063.  
  4064.      Chapter Overview
  4065.      The HDF Environment
  4066.           Machines Supported
  4067.           Language Standards
  4068.      Organization of Source Files
  4069.           Header Files
  4070.           Source Code Files
  4071.      Passing Strings Between FORTRAN and C
  4072.           Passing Strings from FORTRAN to C
  4073.           Passing Strings from C to FORTRAN
  4074.      Function Return Values between FORTRAN and C
  4075.           Differences in Acceptable Routine Names
  4076.           Case Sensitivity
  4077.           How HDF Deals with "All-Upper Case" Compilers 
  4078.       Appended Underscore
  4079.           How HDF Specifies the Appended (and Prepended) Underscore
  4080.           Short Names vs. Long Names
  4081.           ANSI C vs. Old C
  4082.           Type Differences
  4083.           Size Differences
  4084.           Number Representation
  4085.           Byte-order and Structure Representations
  4086.           Access to Library Functions
  4087.  
  4088.  
  4089. Chapter Overview
  4090.  
  4091. The NCSA implementation of HDF is accessible to both C and FORTRAN
  4092. programs and is implemented on many different machines and several
  4093. operating systems. There are important differences between C and
  4094. FORTRAN, as well as between different implementations of each
  4095. language, especially FORTRAN. There are also important differences
  4096. between the different machines and operating systems that HDF
  4097. supports. This chapter describes many of these differences,
  4098. problems and issues associated with them, and methods employed in
  4099. the HDF source code to deal with them.
  4100.  
  4101.  
  4102. The HDF Environment
  4103.  
  4104. The list of machines and operating systems on which HDF is
  4105. implemented is steadily growing. For reasons that should soon be
  4106. clear, the number of platforms on which HDF is officially supported
  4107. is growing slowly. Every time a new platform is added to the list
  4108. of those that HDF supports, additional code must be written that
  4109. takes into account the way memory is organized, the way the
  4110. operating system works, the way numbers are represented, the way
  4111. the file system works, and the way FORTRAN and C works on that
  4112. system.
  4113.  
  4114.  
  4115. Machines Supported
  4116.  
  4117. As of this writing, the following platforms are supported by NCSA's
  4118. HDF group:
  4119.  
  4120.           Cray X-MP and Cray 2 (UNICOS)
  4121.           Sun Systems' Sun 3, Sun 386, and Sparcstation (Unix)
  4122.           Convex (Unix),
  4123.           Macintosh (MPW Shell)
  4124.           IBM PC (MS-DOS)
  4125.           Silicon Graphics (Unix)
  4126.           Vax (VMS)
  4127.           HP 9000 (HPUX)
  4128.           DecStation (Ultrix)
  4129.           IBM RT (Unix)
  4130.  
  4131. In addition to these platforms, HDF has been ported to many other
  4132. platforms for which support cannot currently be provided. These
  4133. include Alliant, Apollo (Domain), HP 3000, Stellar, Amiga,
  4134. Symbolics, NeXT, and IBM 3090 (MVS).
  4135.  
  4136.  
  4137. Language Standards
  4138.  
  4139. Unfortunately, not all compilers are the same. FORTRAN compilers
  4140. often differ in the ways they pass parameters, in the identifier
  4141. naming conventions they employ, and in the number types that they
  4142. support. Similarly, though generally not as drastically, compilers
  4143. differ in the number types that they support and in their adherence
  4144. to the ANSI C standard.
  4145.  
  4146. In order to keep these differences to a minimum, the primary
  4147. dialects used for the source code in the NCSA implementation of RDF
  4148. FORTRAN 77, ANSI C, and "old style C"(1), hereafter referred to as
  4149. "old C". There are very few platforms whose C and FORTRAN compilers
  4150. do not adhere to at least one of these standards. When time and
  4151. resources permit, attempts are also made to support features or
  4152. variations in other dialects of C and FORTRAN, particularly on
  4153. those platforms that are important to NCSA users. Much of the
  4154. remainder of this Chapter speaks to these differences.
  4155.  
  4156. Follow these guidelines
  4157.  
  4158. To all future HDF developers, we cannot overstress the importance
  4159. of following the guidelines outlined in this Chapter. It may take
  4160. longer to write code, and it may be considerably more difficult to
  4161. adapt your coding style to that given here, but the long-term
  4162. benefits in terms of portability and maintenance costs are well
  4163. worth the effort.
  4164.  
  4165.  
  4166. Organization of Source Files
  4167.  
  4168. There are three types of files in the HDF source code directory:
  4169. header files, source code files, and a makefile. Header files and
  4170. source code files are organized by application area. All of the
  4171. functions that apply to a particular application area are stored
  4172. in three source files, and all definitions and declarations that
  4173. apply are stored in a corresponding header file. The makefile
  4174. describes the dependencies among the source and header files, and
  4175. also provides the commands required to compile the corresponding
  4176. libraries and utilities.
  4177.  
  4178.  
  4179. Header Files
  4180.  
  4181. There is one header file for each application area. The HDF Raster
  4182. Image Set interface, for example, has the header file dfr8.h. It
  4183. contains definitions and declarations that are unique to the
  4184. interface.
  4185.  
  4186. (1) "old style C" refers to the version of C described in the first
  4187. edition of The C Programming Language, by Brian Kernighan and
  4188. Dennis Ritchie, published by Prentice-Hall.
  4189.  
  4190. Other header files include:
  4191.  
  4192.                hdf.h
  4193.                hdfi.h
  4194.                hproto.h
  4195.                constants.f
  4196.                functions.f
  4197.  
  4198. hdf.h and hdfi.h.(1) The file hdf.h contains declarations and
  4199. definitions for the common data structures used throughout HDF,
  4200. definitions of the HDF tags, definitions of error numbers, and
  4201. definitions and declarations specific to the general purpose
  4202. interface. Since hdf.h depends on hdfi.h, it includes (via
  4203. #include) hdfi.h.
  4204.  
  4205. The file hdfi.h contains a large amount of information specific to
  4206. the various computing environments supported by HDF. Those
  4207. environmental parameters that need to be set to particular values
  4208. when compiling the HDF library are contained in hdfi.h. Machine
  4209. dependent definitions of such things as number types and macros
  4210. for reading and writing numbers are also included in hdfi.h.
  4211.  
  4212. When porting HDF to a new system, only hdfi.h and the Makefile need
  4213. to be modified.
  4214.  
  4215. Normally it is a good idea to include hdf.h (and therefore
  4216. indirectly hdfi.h) in user programs, though users usually need not
  4217. be aware of their contents.
  4218.  
  4219. hproto.h. This file contains ANSI C prototypes for all HDF C
  4220. routines, and must be include in ANSI-conforming C programs that
  4221. make calls to HDF routines.
  4222.  
  4223. constants.f. This file is for use in FORTRAN programs. It contains
  4224. important constants, such as tag values, that are defined in hdf.h.
  4225. Systems that have FORTRAN preprocessors might be able to include
  4226. these files via #include statements or their equivalent.
  4227.  
  4228. functions.f. This file is for use in FORTRAN programs. It contains
  4229. declarations of all HDF FORTRAN-callable functions. Systems that
  4230. have FORTRAN preprocessors might be able to include these files via
  4231. #include statements or their equivalent.
  4232.  
  4233.  
  4234. Source Code Files
  4235.  
  4236. All HDF operations are performed by routines written in C. Hence,
  4237. even FORTRAN calls to HDF result in calls to the corresponding C
  4238. routines. However, because of the problems described below the
  4239. relationships between the C routines and the corresponding FORTRAN
  4240. routines can be very confusing. Before looking at the specific
  4241. problems, we first describe the C and FORTRAN source file
  4242. organization.
  4243.  
  4244. (1)In earlier implementations of HDF, these files were called df.h
  4245. and dfi.h. Starting with HDF 3.2 the general purpose layer of HDF
  4246. was completely rewritten, and all routine names changed from "df
  4247. ... " to "h ...".
  4248.  
  4249. Each HDF interface typically has four files associated with it. The
  4250. HDF Raster Image Set interface, for example, has four associated
  4251. source files: dfr8.h, dfr8.c, dfr8f.c, dfr8ff.f. The suffixes on
  4252. the filenames indicate their functions, as we describe next.
  4253.  
  4254. The ".h" file is the header file. The other three files, which
  4255. contain the C and FORTRAN functions, are:
  4256.  
  4257. (1)  The "normal" C routines. These routines do all of the actual
  4258.      HDF work. The others have the job of transferring control and
  4259.      data from a FORTRAN environment to a C environment.
  4260.  
  4261.    These routines are stored in files whose names end with ".c",
  4262.    as in "dfr8.c". Every call to HDF, whether it is a C call or a
  4263.    FORTRAN call, ultimately results in a call to one of these
  4264.    routines.
  4265.  
  4266. (2)  C routines that are compatible with FORTRAN and therefore
  4267.      directly callable from FORTRAN.  The primary function of these
  4268.      routines is to provide recognizable function names to the
  4269.      linker. They may also perform operations on data they receive
  4270.      from the FORTRAN routines that call them, such as transferring
  4271.      a FORTRAN string to a local C data area. Examples of how they
  4272.      perform these operations are given below.
  4273.  
  4274.   These routines are stored in files whose names end with "f.c",
  4275.   as in "dfr8f.c" for the raster image interface. The "f" means
  4276.   that the routines are meant to be called from FORTRAN; the "c"
  4277.   means that they are C source code.
  4278.  
  4279. (3)  FORTRAN routines that perform some operation on the parameters
  4280.      that C is unable to perform, before and/or after calling the
  4281.      corresponding C routine. These routines are required, for
  4282.      example, when one of the parameters is a string. The
  4283.      corresponding C routine has no way of knowing the length of
  4284.      the string unless it is explicitly given the length by the
  4285.      FORTRAN routine.
  4286.  
  4287.   These routines are stored in files whose names end with "ff.f",
  4288.   as in "dfr8ff.f" for the raster image interface. The "f' means
  4289.   that the routines are to be called from FORTRAN; the first "f"
  4290.   means that they perform some FORTRAN operation that C cannot
  4291.   perform; the second "f" means that they are FORTRAN source code.
  4292.  
  4293. The roles of these different types of source file types will become
  4294. clearer as we look at some of the problems that arise in
  4295. interfacing C and many different implementations of FORTRAN.
  4296.  
  4297.  
  4298. File naming conventions
  4299.  
  4300. The naming conventions for HDF library source code files are
  4301. complicated by several factors. Because of the wide variety of
  4302. platforms which HDF must accommodate, all files that will compile
  4303. to object modules in the HDF library must have names that are
  4304. unique in the first 8 characters, ignoring case. The difficulties
  4305. involved in maintaining a Fortran-callable interface to a library
  4306. that is primarily written in C further complicate the naming of
  4307. source code files.
  4308.  
  4309.  
  4310. Passing Strings between FORTRAN and C
  4311.  
  4312. One of the most important differences between FORTRAN and C
  4313. compilers is in the way strings are represented. Different
  4314. compilers use different data structures for strings, and supply
  4315. string length information in different ways.
  4316.  
  4317.  
  4318. Passing Strings from FORTRAN to C
  4319.  
  4320. When strings are passed between FORTRAN and C routines, they may
  4321. need to be converted from one representation to the other. C
  4322. compilers store strings in an array of type char, terminated by a
  4323. NULL byte ('\0'). The name of a string variable is a pointer to the
  4324. address of the first character in the string. FORTRAN compilers are
  4325. not consistent in the ways that they store strings.
  4326.  
  4327. Two pieces of information are needed in order to pass a string from
  4328. FORTRAN to C: its length and its address.
  4329.  
  4330. The first problem is solved by invoking the standard FORTRAN
  4331. function len(), which returns the length of a string. Since C
  4332. expects a '\0' (NULL) byte at the end of strings, care must be
  4333. taken that this NULL byte does not overwrite useful information in
  4334. the FORTRAN string.
  4335.  
  4336. The second problem is more difficult because of the different ways
  4337. that different FORTRANs store string.
  4338.  
  4339. To solve this, a macro_fcdtocp ("FORTRAN character descriptor to
  4340. C pointer) is used. _fcdtocp is defined differently, depending on
  4341. the machine on which it is compiled. Here are some different ways
  4342. that _fcdtocp works:
  4343.  
  4344. There are three different ways that a FORTRAN string's address can
  4345. be passed to C:
  4346.  
  4347. * UNICOS FORTRAN stores strings in a structure called '_fcd"
  4348.   (FORTRAN character descriptor). '_fcdtocp' is a built-in function
  4349.   in UNICOS that returns the address of the string.
  4350.  
  4351. * VMS FORTRAN stores strings by means of a string descriptor
  4352.   structure that provides information about where the string is
  4353.   stored and its length. When compiled under VMS, the function
  4354.   _fcdtocp extracts the string's address and returns that value.
  4355.  
  4356. * Most other FORTRAN compilers supported by HDF store strings just
  4357.   as C does, in character arrays with the array name identifying
  4358.   the array's address. For these compilers nothing special need be
  4359.   done in passing a string from FORTRAN to C.
  4360.  
  4361. In HDF, a FORTRAN call that involves passing a string results in
  4362. the following sequences of actions:
  4363.  
  4364. (1) A FORTRAN "stub" determines the length and address in memory
  4365.     of the string. Since this is a FORTRAN routine, it can be found
  4366.     in the file.
  4367.  
  4368. (2) The FORTRAN stub then calls a C routine, which it passes all
  4369.     parameters from the initial call, plus one extra parameter: the
  4370.     string's length.
  4371.  
  4372. (3) The C routine converts the FORTRAN string to a C string by
  4373.     copying it to a C array of type char, and appending a '\0'
  4374.     byte. Since this C routine serves as a link between a FORTRAN
  4375.     stub and the corresponding C interface call, it can be found
  4376.     in the " ... f.c" file.
  4377.  
  4378. (4) This C routine then calls the HDF C routine that performs the
  4379.     actual function.
  4380.  
  4381. This process is illustrated in Figure 7.1
  4382.  
  4383. *** INSERT FIGURE HERE ***
  4384.  
  4385.  
  4386. Passing Strings from C to FORTRAN
  4387.  
  4388. When strings are passed from C to FORTRAN, the reverse procedure
  4389. is followed. First, a string pointer is obtained within the FORTRAN
  4390. routine's data area. (It is assumed that the space pointed to has
  4391. already been allocated, and is sufficiently large to hold the
  4392. string.) The string is then copied from the C data area to the
  4393. FORTRAN data area. Finally, if necessary the FORTRAN string's data
  4394. area is padded with blanks.
  4395.  
  4396.  
  4397. Function Return Values between FORTRAN and C
  4398.  
  4399. When a FORTRAN routine calls a C function, it always expects a
  4400. return value from that function. Unfortunately, the form in which
  4401. C functions return arguments is not always compatible with the form
  4402. in with FORTRAN expects them.
  4403.  
  4404. To solve this problem, some C compilers offer the option of
  4405. controlling the form of the return value from a function. For
  4406. example, Language Systems FORTRAN for the Macintosh requires that
  4407. all C function declarations be prepended by the word "pascal" so
  4408. that the return value can be recognized by a FORTRAN routine that
  4409. calls it, as in:
  4410.  
  4411. pascal int dsgrang(void *pmax, void *pmin)
  4412.  
  4413. Since C always expects return values to be passed "by value" rather
  4414. than, say, "by reference," it is important to coerce FORTRAN
  4415. functions to do the same. This is accomplished by defining a macro
  4416. FRETVAL that is prepended to the declaration of every FORTRAN-
  4417. callable C function. For example:
  4418.  
  4419.           FRETVAL (int)
  4420. dsgrang(void *pmax, void *pmin)
  4421.  
  4422. If Language Systems FORTRAN is to be used, then FRETVAL is defined
  4423. (in hdfi.h) as follows:
  4424.  
  4425. #if defined(MAC)           /* with LS FORTRAN */
  4426. #  define FRETVAL(X)       pascal x
  4427. #endif
  4428.  
  4429.  
  4430. Differences in Acceptable Routine Names
  4431.  
  4432. Different FORTRAN compilers impose different restrictions on the
  4433. length, character set, and form of identifiers. In general, HDF
  4434. uses C conventions for naming routines, and this means that
  4435. measures must be taken to accommodate those compilers which have
  4436. different conventions than C.
  4437.  
  4438. The method used in HDF is to name routines differently, depending
  4439. on the particular conventions of the FORTRAN compiler being used.
  4440. This is done by defining certain flags for the preprocessor via
  4441. #define statements in the hdfi.h file. Then conditional
  4442. compilation--via #ifdef statements in.the source code files--is
  4443. used to compile the routines that are called from FORTRAN with
  4444. names that that particular FORTRAN can understand.
  4445.  
  4446.  
  4447. Case Sensitivity
  4448.  
  4449. C compilers are case sensitive. That is, upper and lower case
  4450. letters are different. Many FORTRAN compilers allow users to use
  4451. upper and lower case letters in naming routines, but the symbol
  4452. table names that they produce in object modules are all in upper
  4453. case or all in lower case. These compilers are not case sensitive.
  4454. If routines compiled by a case-sensitive compiler are to be linked
  4455. with routines compiled by a compiler that is not case sensitive,
  4456. they might not recognize one another's routines.
  4457.  
  4458. For example, the UNICOS FORTRAN compiler allows you to name
  4459. routines without regard to case, but produces object modules with
  4460. all routine names converted to upper case. UNICOS C, on the other
  4461. hand, performs no such conversion. Consider how the HDF routine
  4462. Hopen is treated by the two compilers.
  4463.  
  4464. Hopen is written in C, so the HDF library has the name 'Hopen', a
  4465. mixed-case name, in its symbol table. Suppose you make the
  4466. following call in your UNICOS FORTRAN program:
  4467.  
  4468. file_id = Hopen('myfile', ... )
  4469.  
  4470. The FORTRAN compiler will create an object module with the routine
  4471. name "HOPEN" (all upper case) in its symbol table. When you link
  4472. it to the HDF library, it will find "Hopen", but not "HOPEN", and
  4473. will generate an "unsatisfied external reference" error.
  4474.  
  4475. So far there are three FORTRAN compilers supported by HDF that
  4476. convert names to upper case in the symbol table:
  4477.  
  4478.      VMS FORTRAN
  4479.      UNICOS FORTRAN
  4480.      Language Systems FORTRAN.
  4481.  
  4482.  
  4483. How HDF Deals with "All-Upper Case" Compilers
  4484.  
  4485. The solution to this problem is to name C functions entirely in
  4486. upper case whenever they are called by all-upper case FORTRAN
  4487. routines. This is done as follows: For FORTRAN compilers that
  4488. produce all upper case symbol table entries a flag "DF_CAPFNAMES"
  4489. is defined via a #define in hdfi.h. Then conditional compilation
  4490. is used in the source code files to compile the routines that are
  4491. called from FORTRAN with all-upper case names.
  4492.  
  4493. For example, since UNICOS FORTRAN produces all-upper case symbol
  4494. table entries, there is in the UNICOS section of hdfi.h. the
  4495. following line:
  4496.  
  4497. #define DF_CAPFNAMES
  4498.  
  4499. Correspondingly, there are conditional compilations in the "..f.c"
  4500. files that produce all-upper case routine names. For example, the
  4501. function name "Fun" can be redefined at "FUN" as follows:
  4502.  
  4503. #ifdef DF_CAPFNAMES
  4504.     define Fun  FUN
  4505.     #endif /* DF_CAPFNAMES */
  4506.  
  4507.  
  4508. Appended Underscore
  4509.  
  4510. A similar problem occurs with respect to the underscore character.
  4511. When compilers generate object module symbol tables from source
  4512. code, they commonly prepend an underscore ('_') to all external
  4513. symbols. C generally does this. Then, when linking occurs, the
  4514. linker looks for external symbols in the symbol table with the
  4515. prefix.
  4516.  
  4517. Unfortunately, many FORTRAN compilers also append an underscore to
  4518. identify external symbols. Since C does not generally do this,
  4519. external references in FORTRAN-generated object modules will not
  4520. recognize externals with the same names in C-generated modules.
  4521.  
  4522. For example, the FORTRAN compiler on the CONVEX, places an
  4523. underscore at the end of routine names, while the C compiler only
  4524. places an underscore at the front. Consider how a C function called
  4525. FUN would be treated in this context.
  4526.  
  4527. Since FUN is a C function, the object module containing FUN has it
  4528. stored under the name "_FUN". Suppose you make the following call
  4529. in a FORTRAN program:
  4530.  
  4531. x = FUN (y)
  4532.  
  4533. The FORTRAN compiler creates an object module with the routine name
  4534. "_ FUN_" in its symbol table. When you link it to the C module, it
  4535. will find " FUN", but not "_FUN_", and will generate an
  4536. "unsatisified external reference error."
  4537.  
  4538.  
  4539. How HDF Specifies Appended (and Prepended) Underscores
  4540.  
  4541. The solution to this problem is to name C functions with an
  4542. appended underscore whenever one is expected by FORTRAN calling
  4543. routines. For instance, if the name of FUN had been "FUN_" in the
  4544. example, its name in the C object module would have been "_FUN_",
  4545. which is exactly what FORTRAN put into its symbol table.
  4546.  
  4547. This is done as follows: For every machine whose FORTRAN compiler
  4548. requires appended underscores, a flag "FNAME_POST_UNDERSCORE" is
  4549. defined via a #define in hdfi.h in the section associated with that
  4550. machine. Similarly, for those that require a prepended underscore
  4551. a flag "FNAME_PRE_UNDERSCORE" is defined. Then, in a section of
  4552. code in hdfi.h, conditional compilation is used to define a macro
  4553. called "FNAME" that appends and/or prepends underscores as
  4554. required.
  4555.  
  4556. In the modules in which routines are actually defined (including
  4557. in hptroto.h), the FNAME macro is then applied to each routine,
  4558. causing the appropriate underscores to be added.
  4559.  
  4560. Hence, in the example above in which "Fun" was caused to be
  4561. uppercase, the actual definition would be as follows:
  4562.  
  4563. #ifdef DF_CAPFNAMES
  4564.      define Fun     FNAME(FUN)
  4565. #endif /* DF_CAPFNAMES */
  4566.  
  4567.  
  4568. Short Names vs. Long Names
  4569.  
  4570. In the C implementations supported by HDF, identifiers may be any
  4571. length, with at least the first 31 characters having significance.
  4572. FORTRAN compilers differ in the maximum lengths of identifiers that
  4573. they allow, but all of those supported by HDF allow identifiers to
  4574. have at least seven characters.
  4575.  
  4576. To deal with the discrepancies between identifier lengths allowed
  4577. by C and those allowed by the various FORTRAN compilers, a set of
  4578. equivalent short names has been devised that can be used when
  4579. programming in FORTRAN. For all HDF routines with names that are
  4580. more than seven characters long, there is an identical routine
  4581. whose name is eight or fewer characters long.
  4582.  
  4583. For example, for the routine "DFSDgetdims" in the file dfsd.c there
  4584. is a corresponding routine "dsgdims" in the file dfsdff.f with
  4585. exactly the same functionality.
  4586.  
  4587.  
  4588. ANSI C vs. Old C
  4589.  
  4590. Both ANSI and old C compilers are supported in the current
  4591. implementation of HDF (HDF 3.2). ANSI C is preferred, because it
  4592. has many features that help insure portability, but unfortunately
  4593. many important platforms do not support full ANSI C. The HDF code
  4594. determines whether or not ANSI C is available from the flag _STDC_.
  4595. If ANSI C is available, then _STDC_ is defined.(1)
  4596.  
  4597. The most noticeable difference between ANSI and old C is in the way
  4598. functions are declared. For example, in ANSI C the function
  4599. DFSDsetdims() is declared with
  4600.  
  4601. int DFSDsetdims(intn rank, int32 dimsizes[])
  4602.  
  4603. (1) Some C compilers are not entirely ANSI-conforming, yet they
  4604. conform well enough that the HDF implementation can treat them as
  4605. if they were. In such cases, it is considered permissible to
  4606. "#define" _STDC_ when compiling.
  4607.  
  4608. In old C the same function is declared with
  4609.  
  4610. int DFSDsetdims(rank, dimsizes)
  4611. intn rank;
  4612. int32   dimsizes[];
  4613.  
  4614. The NCSA implementation of HDF accommodates these differences by
  4615. defining in hdfi.h a flag called PROTOTYPE, which is used for every
  4616. function declaration, as in the following example.
  4617.  
  4618. #ifdef PROTOTYPE
  4619. int DFSDsetdims(intn rank, int32 dimsizes[])
  4620. #else
  4621. int DFSDsetdims(rank, dimsizes)
  4622. intn rank;
  4623. int32   dimsizes[];
  4624. #endif /* PROTOTYPE */
  4625.  
  4626. Another big difference between K&R and ANSI C is that ANSI C allows
  4627. the use of function prototypes that include arguments, which helps
  4628. enormously in detecting errors in the number and types of
  4629. arguments. Old C also allows the use of function prototypes, but
  4630. without the argument list. This difference occurs whenever
  4631. PROTOTYPE is defined, it is handled by means of a macro called
  4632. PROTO, which is defined as follows:
  4633.  
  4634. #ifdef  PROTOTYPE
  4635. #define         PROTO(x) x
  4636. #else
  4637. #define         PROTO(x)  ()
  4638. #endif
  4639.  
  4640. This macro is applied as in the following example:
  4641.  
  4642. extern int32 Hopen
  4643. PROTO((char *path, intn access, int16 ndds));
  4644.  
  4645. When PROTOTYPE is defined, PROTO causes the argument list to stay
  4646. as it is. When PROTOTYPE is not defined, PROTO causes the argument
  4647. list to disappear.
  4648.  
  4649.  
  4650. Type Differences
  4651.  
  4652. Different machines and compilers differ in the sizes of numbers
  4653. that they assign to different data types, in their representations
  4654. of different number types, and in the way they organize aggregates
  4655. of numbers (especially structures).
  4656.  
  4657.  
  4658. Size differences
  4659.  
  4660. The same number type can be different sizes on different machines.
  4661. Type int, for example, is 16 bits to many IBM PC compilers, 48 bits
  4662. to some supercomputer compilers, and 32 bits on most others. These
  4663. differences can cause insidious problems in code like the HDF code
  4664. that depends in so many places on numbers being the right size.
  4665.  
  4666. This problem is handled in HDF by insisting in the code that all
  4667. variables and functions must use a typedef'ed type which fully
  4668. defines their type, including the number of bits that they occupy.
  4669. This includes all parameters, members of structures, and static,
  4670. automatic, and external variables.
  4671.  
  4672. Hence, the data types used in HDF include the following. (The
  4673. prefix "u" stands for "unsigned".)
  4674.  
  4675.           int8
  4676.           uint8
  4677.           int16
  4678.           uint16
  4679.           int32
  4680.           uint32
  4681.           float32
  4682.           float64
  4683.           intn
  4684.           uintn
  4685.  
  4686. So, for example, on Sun's C compiler uint32 is defined with
  4687.  
  4688. typedef long int int32;
  4689.  
  4690. Hence, for each machine, typedefs are declared that map all of the
  4691. data types used into the best available types.
  4692.  
  4693. Unfortunately, it is not always possible to find a local data type
  4694. that maps exactly to one of these types. For example, the Cray
  4695. UNICOS C compiler does not support a 16-bit data type. In such
  4696. instances, we do the best we can and try to be on the lookout for
  4697. potential problems with number sizes.
  4698.  
  4699. The data types "intn" and uintn are to be used whenever it can be
  4700. determined that number type size is of no consequence, and that a
  4701. 16-bit integer is large enough to hold any value the number can
  4702. have. In such cases, the native int (or unsigned int) type of the
  4703. host machine is used. Experience has shown that substantial
  4704. performance gains can be achieved by using intn or uintn in certain
  4705. circumstances.
  4706.  
  4707.  
  4708. Number Representation
  4709.  
  4710. One of the keys to producing a portable file format is insuring
  4711. that numbers that are represented differently on different machines
  4712. somehow get converted correctly when moved from machine to machine.
  4713. The approach taken to this in the NCSA implementation is to provide
  4714. conversion routines to convert between local representations and
  4715. a standard representation that is stored in HDF files. Details of
  4716. this process will be included in a later edition of this manual.
  4717.  
  4718.  
  4719. Byte-order and Structure Representations
  4720.  
  4721. Even when the basic bit-representation of constants or aggregates
  4722. like structures is the same between machines, the ways that the
  4723. bits are packed into a word, and the order in which the bits are
  4724. layed out, can differ among machines. For example, Digital machines
  4725. and Intel-based machines generally order bytes differently from
  4726. most others. And the C compiler on a Cray, whose word size is 64
  4727. bits, packs structures differently from one on machines whose word
  4728. size is 32 bits.
  4729.  
  4730. Differences in byte order among machines are handled in two ways.
  4731. when the data to be written (or read) consists of non-integer data
  4732. and/or a large array or any type of data, a conversion routine
  4733. (mentioned in the previous section, "Number Representation") is
  4734. invoked. When an individual integer is to be written (or read), an
  4735. "ENCODE" or "DECODE" macro is used.
  4736.  
  4737. There are ENCODE and DECODE macros for 16-bit and 32-bit integers:
  4738.  
  4739.      INT16ENCODE
  4740.      UINT16ENCODE
  4741.      INT32ENCODE
  4742.      UINT32ENCODE
  4743.      INT16DECODE
  4744.      UINT16DECODE
  4745.      INT32DECODE
  4746.      UINT32DECODE
  4747.  
  4748. The ENCODE macros are written in such a way that they write
  4749. integers to an HDF file in a standard way, no matter what the
  4750. corresponding word-size and byte order are of the host machine.
  4751.  
  4752. Likewise, Tthe DECODE macros are written in such a way that they
  4753. read integers stored in a standard way in an HDF file and store the
  4754. integers in the required byte order and word size on the host
  4755. machine.
  4756.  
  4757. Since the ENCODE and DECODE macros deal with both byte order and
  4758. word size, they are also used to handle the reading and writing of
  4759. record-like structures. For example, the structure for an HDF data
  4760. descriptor consists of two 16-bit fields, followed by two 32-bit
  4761. fields, as implied by the following C declaration:
  4762.  
  4763.           struct {
  4764.                uint16 tag;
  4765.                uint16 ref;
  4766.                uint32 offset;
  4767.                uint32 length;
  4768.           }
  4769.  
  4770. In an HDF file this structure must occupy exactly 12 bytes. On one
  4771. computer it might occupy 12 bytes of storage, and on another, such
  4772. as the Cray, it might occupy 32 bytes. Furthermore some machines
  4773. might represent the numbers internally in different byte orders
  4774. than others. By using the ENCODE and DECODE macros we are able to
  4775. insure that these values are represented correctly in all machines
  4776. and in HDF files.
  4777.  
  4778.  
  4779. Access to Library Functions
  4780.  
  4781. Despite efforts to standardize them, function libraries often
  4782. differ in significant ways. There are at least three types of
  4783. functions that need special treatment in the HDF implementation:
  4784.  
  4785. (1) All file I/0 access. Both the stream and system level functions
  4786.     need this (i.e. the functions associated with the fopen() call,
  4787.     and the functions associated with the open() call). This is
  4788.     generally a 16-bit vs. 32-bit problem, because some machines
  4789.     use 16-bit values for the size of and the number of elements
  4790.     to write/read, and others use 32-bit values.
  4791.  
  4792. (2) All memory allocation and releasing. There are two different
  4793.     problems associated with this. The first is that on a 16-bit
  4794.     machine, a 16-bit value is used for the number of bytes to
  4795.     allocate at one time. The second is that certain operating
  4796.     systems (notably MS-Windows and MAC/OS) don't have malloc() and
  4797.     free() calls. These operating systems use handles for
  4798.     allocating memory and require different function calls for
  4799.     memory allocation.
  4800.  
  4801. (3) Memory and string manipulation. These functions (such as
  4802.     memcpy(), memcmp(), strcpy(), strlen(), etc.) require slightly
  4803.     different function names under different memory models in
  4804.     MS-DOS and under MS-Windows than on most other systems.
  4805.  
  4806. These differences are dealt with by defining macros for the
  4807. relevant functions, and defining them appropriately in the
  4808. machine-specific sections of hdfi.h.
  4809.