Class hdatt
The attribute tool reads and writes HDF file attributes.
Name
hdatt - reads or writes HDF file attributes.
Synopsis
hdatt [OPTIONS] input
Options:
-h, --help
-n, --name=STRING
-t, --type=TYPE
-l, --value=STRING1[/STRING2/...]
-V, --variable=STRING
--version
Description
The attribute tool reads or writes HDF file attributes using the HDF Scientific Data Sets (SDS) interface. The two modes work as follows:
- Read mode
- In read mode, the tool can read from either the global attribute set (the default), or the attribute set specific to a variable (when then --variable option is specified). It can read either all attribute values in the set (the default), or just a single attribute value (when the --name option is specified).
- Write mode
- Write mode is specified by the use of the --value option, which provides a value for a named attribute. In write mode, the user is required to supply an attribute name and value, and optionally a type. If no type is specified, the type defaults to 'string' (see the --type option below for the meanings of various type names). Attributes may be written to the global attribute set (the default), or to specific variables in the data file using the --variable option.
Note: The attribute tool is currently limited to reading and writing only the signed HDF data types. In read mode, unsigned HDF attribute data are read correctly, but the value displayed as if it were signed.
Parameters
Main parameters:
- input
- The input data file name.
Options:
- -n, --name=STRING
- The name of the attribute to read or write.
- -t, --type=TYPE
- The attribute data type (write mode only). The valid types and
their HDF equivalents are as follows:
Attribute Types Type name HDF type string DFNT_CHAR8 byte DFNT_INT8 short DFNT_INT16 int DFNT_INT32 long DFNT_INT64 float DFNT_FLOAT32 double DFNT_FLOAT64 - -l, --value=STRING1[/STRING2/...]
- The value(s) for the named attribute. If specified, this places the tool into write mode, and --name must specify an attribute name. If an attribute already exists, its value is overwritten with the new value. If an attribute with the name does not exist, it is created and the new value assigned to it. By default if this option is not used, the tool is in read mode.
- -V, --variable=STRING
- The variable to read or write the attribute data. By default, the attribute is read from or written to the global attribute set.
- --version
- Prints the software version.
Exit status
0 on success, > 0 on failure. Possible causes of errors:
- Invalid command line option
- Invalid input or output file names
- Invalid variable name
- Invalid attribute name in read mode
- Invalid attribute type in write mode
- Value does not convert to the specified attribute data type
Examples
As an example of read mode, the following command reads and prints all the global attribute data from a CoastWatch HDF file:
phollema$ hdatt 2005_095_1522_n17_er.hdf satellite = noaa-17 sensor = avhrr origin = USDOC/NOAA/NESDIS CoastWatch cwhdf_version = 3.2 pass_type = day pass_date = 12878 start_time = 55371.0 projection_type = mapped projection = Mercator gctp_sys = 5 gctp_zone = 0 gctp_parm = 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 gctp_datum = 12 et_affine = 0.0 -1470.0 1470.0 0.0 -8804259.100925786 5723777.271647277 rows = 1401 cols = 1302 polygon_latitude = 45.83810150571052 45.83810150571052 45.83810150571052 45.83810150571052 45.83810150571052 42.51315402540104 38.99999999998719 35.30179546333813 31.424886223357582 31.424886223357582 31.424886223357582 31.424886223357582 31.424886223357582 35.30179546333813 38.99999999998719 42.51315402540104 45.83810150571052 polygon_longitude = -79.09000515710031 -74.79500257855015 -70.5 -66.20499742144985 -61.90999484289969 -61.90999484289969 -61.90999484289969 -61.90999484289969 -61.90999484289969 -66.20499742144985 -70.5 -74.79500257855015 -79.09000515710031 -79.09000515710031 -79.09000515710031 -79.09000515710031 -79.09000515710031 history = cwimport product.tshdf product.hdf
To dump only a single attribute:
phollema$ hdatt --name satellite 2005_095_1522_n17_er.hdf noaa-17
or a single attribute from a specific variable:
phollema$ hdatt --name units --variable avhrr_ch3a 2005_095_1522_n17_er.hdf albedo*100%
As an example of write mode, suppose that we wanted to save the date when the file was originally downloaded from the server:
phollema$ hdatt --name download_date --value "Mon Apr 11 18:20:15 PDT 2005" 2005_095_1522_n17_er.hdf
Now suppose we wanted to assign an integer quality value of 65% to the file based on some test that was performed on the file data:
phollema$ hdatt --name quality_value --value 65 --type int 2005_095_1522_n17_er.hdf
Finally, suppose that we wanted to change the units and scaling factor / offset of a variable, originally in degrees Celsius and scaled by 0.01, to degrees Fahrenheit:
phollema$ hdatt --name units --value "deg F" --variable sst 2005_095_1522_n17_er.hdf phollema$ hdatt --name scale_factor --value 0.018 --type double --variable sst 2005_095_1522_n17_er.hdf phollema$ hdatt --name add_offset --value -1777.777777 --type double --variable sst 2005_095_1522_n17_er.hdf
- Since:
- 3.2.0
- Author:
- Peter Hollemans
-
Method Summary
-
Method Details
-
main
Performs the main function.- Parameters:
argv
- the list of command line parameters.
-