File: he5_pt_readdata.c

package info (click to toggle)
hdf-eos5 2%3A2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,692 kB
  • sloc: ansic: 92,051; fortran: 31,463; sh: 11,395; makefile: 492
file content (190 lines) | stat: -rwxr-xr-x 5,994 bytes parent folder | download | duplicates (3)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 ----------------------------------------------------------------------------
 |    Copyright (C) 1999   Emergent IT Inc. and Raytheon Systems Company    |
 ----------------------------------------------------------------------------
 */


#include <HE5_HdfEosDef.h>

int main()
{
  herr_t          status = FAIL;/* return status variable         */

  hid_t           ptfid = FAIL; /* HDFEOS Point file ID           */
  hid_t           PTid  = FAIL; /* Point structure ID             */

  int             i, j;        /* Loop indices                    */
  int             nflds = FAIL;/* Number of level fields          */
  int             IntAttr;     /* Integer attribute value         */

  long            nattr;       /* Number of attributes            */
  long            strbufsize;  /* Size of attribute list buffer   */

  hsize_t         nrecs = 0;   /* Number of records in a level    */

  size_t          datasize = 0;/* Size (in bytes) of data to read */

  HE5_CmpDTSinfo  level;      /* Level information data structure */
  HE5_CmpDTSinfo  inInfo;     /* Input information data structure */
  HE5_CmpDTSinfo  inInfo2;    /* Input information data structure */


  /* User-defined structure to read level data to */
  /* -------------------------------------------- */
  typedef struct {
          double   time;
          float    con[4];
          char     spec[8];
        } Sensor;

  Sensor   s[50];

  double   s1[50];


  /* Open the HDF-EOS file, "Point.h5" */
  /* --------------------------------- */
  ptfid = HE5_PTopen("Point.h5", H5F_ACC_RDONLY);
  printf("File ID returned by HE5_PTopen() :           %ld \n", (long) ptfid);

  /* Read Simple Point */
  /* ----------------- */
  PTid = HE5_PTattach(ptfid, "Simple Point");
  printf("Point ID returned by HE5_PTattach() :        %ld \n", (long) PTid);

  /* Get level information */
  /* --------------------- */
  status = HE5_PTlevelinfo(PTid, 0, &level);
  printf("Status returned by HE5_PTlevelinfo() :       %d \n", status);

  nflds = level.nfields;
  printf("Number of fields in level:   %d \n", nflds);
  for (i = 0; i < nflds; i++)
	{
	  printf("Field name:                  %s \n", level.fieldname[i]);
	  printf("Field rank:                  %d \n", level.rank[i]);
	  printf("Field type ID:               %ld \n", (long) level.dtype[i]);
	  for (j = 0; j < level.rank[i]; j++)
		printf("Field dims:                  %d \n", (int)level.dims[i][j]);
	  printf("Field class:                 %d \n", level.dclass[i]);
	}

  /* Get the number of records in level */
  /* ---------------------------------- */
  nrecs = HE5_PTnrecs(PTid, 0);
  printf("Number of records in level:  %lu \n", (unsigned long)nrecs);

  /* Set the data size */
  /* ----------------- */
  datasize = (size_t)sizeof(Sensor);

  /* Populate input information structure */
  /* ------------------------------------ */
  inInfo.nfields    = nflds;
  inInfo.datasize   = (size_t)sizeof(Sensor);

  inInfo.rank[0]    = 1;
  inInfo.rank[1]    = 1;
  inInfo.rank[2]    = 1;

  inInfo.offset[0]  = HOFFSET(Sensor, time);
  inInfo.offset[1]  = HOFFSET(Sensor, con);
  inInfo.offset[2]  = HOFFSET(Sensor, spec);

  inInfo.dtype[0]   = H5T_NATIVE_DOUBLE;
  inInfo.dtype[1]   = H5T_NATIVE_FLOAT;
  inInfo.dtype[2]   = H5T_NATIVE_CHAR;

  inInfo.dclass[0]  = H5T_NO_CLASS;
  inInfo.dclass[1]  = H5T_NO_CLASS;
  inInfo.dclass[2]  = H5T_NO_CLASS;

  inInfo.dims[0][0] = 1;
  inInfo.dims[1][0] = 4;
  inInfo.dims[2][0] = 8;

  inInfo.array[0] = 0;
  inInfo.array[1] = 1;
  inInfo.array[2] = 1;

  for( i = 0; i < nflds; i++)
  {
	inInfo.fieldname[i] = (char *)calloc(64, sizeof(char));
	strcpy(inInfo.fieldname[i], level.fieldname[i]);
  }

  /* Read the level data */
  /* ------------------- */
  status = HE5_PTreadlevel(PTid, 0, &inInfo, &datasize, s);
  printf("Status returned by HE5_PTreadlevel() :       %d \n", status);
  for (i = 0; i < nrecs; i++)
	printf("%lf  %f  %f  %f  %f  %s\n", s[i].time, s[i].con[0], s[i].con[1], s[i].con[2], s[i].con[3], s[i].spec);


  /* Release memory */
  /* -------------- */
  for (i = 0; i < nflds; i++)
	if (inInfo.fieldname[i] != NULL) free(inInfo.fieldname[i]);

  /* Set the data size */
  /* ----------------- */
  datasize = (size_t)sizeof(double);

  /* Populate input information structure */
  /* ------------------------------------ */
  inInfo2.nfields    = 1;
  inInfo2.datasize   = (size_t)sizeof(double);

  inInfo2.rank[0]    = 1;

  inInfo2.offset[0]  = 0;

  inInfo2.dtype[0]   = H5T_NATIVE_DOUBLE;

  inInfo2.dclass[0]  = H5T_FLOAT;

  inInfo2.dims[0][0] = 1;

  inInfo2.array[0]   = 0;

  inInfo2.fieldname[0] = (char *)calloc(64, sizeof(char));
  strcpy(inInfo2.fieldname[0], level.fieldname[0]);

  /* Read the level data */
  /* ------------------- */
  status = HE5_PTreadlevel(PTid, 0, &inInfo2, &datasize, s1);
  printf("Status returned by HE5_PTreadlevel() :       %d \n", status);
  for (i = 0; i < nrecs; i++)
	printf("%lf \n", s1[i]);

  /* Release memory */
  /* -------------- */
  if (inInfo2.fieldname[0] != NULL)
	free(inInfo2.fieldname[0]);

  for (i = 0; i < nflds; i++)
	if(level.fieldname[i] != NULL) H5free_memory(level.fieldname[i]);

  status = HE5_PTdetach(PTid);
  printf("Status returned by HE5_PTdetach() :          %d \n", status);

  PTid = HE5_PTattach(ptfid, "FixedBuoy Point");
  printf("Point ID returned by HE5_PTattach() :        %ld \n", (long) PTid);

  /* Read Fixed Buoy Point Attributes */
  /* -------------------------------- */
  nattr  = HE5_PTinqattrs(PTid, NULL, &strbufsize);
  status = HE5_PTreadattr(PTid, "GlobalAttr_Integer", &IntAttr);
  printf("Status returned by HE5_PTreadattr() :        %d \n", status);
  printf(" \n");
  printf("Integer attribute value:                     %d\n", IntAttr);

  status = HE5_PTdetach(PTid);
  printf("Status returned by HE5_PTdetach() :          %d \n", status);

  status = HE5_PTclose(ptfid);
  printf("Status returned by HE5_PTclose() :           %d \n", status);

  return 0;
}