File: SD_set_attr.c

package info (click to toggle)
libhdf4 4.2.10-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,488 kB
  • ctags: 12,954
  • sloc: ansic: 146,962; sh: 14,905; fortran: 12,480; makefile: 922; yacc: 680; pascal: 418; lex: 170; csh: 41
file content (76 lines) | stat: -rw-r--r-- 2,138 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "mfhdf.h"

#define FILE_NAME      "SDS.hdf"
#define FILE_ATTR_NAME "File_contents"
#define SDS_ATTR_NAME  "Valid_range"
#define DIM_ATTR_NAME  "Dim_metric"

int main()
{
   /************************* Variable declaration **************************/

   int32   sd_id, sds_id, sds_index;
   intn    status;
   int32   dim_id, dim_index;
   int32   n_values;                /* number of values of the file, SDS or
                                       dimension attribute         */
   char8   file_values[] = "Storm_track_data"; 
                                   /* values of the file attribute */
   float32 sds_values[2] = {2., 10.};
                                   /* values of the SDS attribute  */
   char8   dim_values[]  = "Seconds"; 
                                  /* values of the dimension attribute */

   /********************* End of variable declaration ***********************/

   /*
   * Open the file and initialize the SD interface.
   */
   sd_id = SDstart (FILE_NAME, DFACC_WRITE);

   /*
   * Set an attribute that describes the file contents.
   */
   n_values = 16;
   status = SDsetattr (sd_id, FILE_ATTR_NAME, DFNT_CHAR, n_values, 
                       (VOIDP)file_values);

   /*
   * Select the first data set.
   */
   sds_index = 0;
   sds_id = SDselect (sd_id, sds_index);

   /* 
   * Assign attribute to the first SDS. Note that attribute values
   * may have different data type than SDS data.
   */
   n_values  = 2;
   status = SDsetattr (sds_id, SDS_ATTR_NAME, DFNT_FLOAT32, n_values, 
                       (VOIDP)sds_values);

   /*
   * Get the the second dimension identifier of the SDS.
   */
   dim_index = 1;
   dim_id = SDgetdimid (sds_id, dim_index);

   /*
   * Set an attribute of the dimension that specifies the dimension metric.
   */
   n_values = 7;
   status = SDsetattr (dim_id, DIM_ATTR_NAME, DFNT_CHAR, n_values, 
                       (VOIDP)dim_values);

   /*
   * Terminate access to the data set.
   */
   status = SDendaccess (sds_id);

   /*
   * Terminate access to the SD interface and close the file.
   */
   status = SDend (sd_id);

   return 0;
}