File: he5_sw_info.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 (279 lines) | stat: -rwxr-xr-x 10,686 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 ----------------------------------------------------------------------------
 |    Copyright (C) 1999   Emergent IT Inc. and Raytheon Systems Company    |
 ----------------------------------------------------------------------------
 */



#include      <HE5_HdfEosDef.h>

/*  In this program we retrieve information about (1) dimensions, (2)  */
/*   dimension mappings (geolocation relations), (3) swath fields,     */
/*     and (4) the global/group/local attributes                       */
/* ------------------------------------------------------------------- */

int main()
{
  herr_t          status = FAIL;

  int             i, rk, *rank, rk1, chunk_rank;

  hid_t           swfid = FAIL, SWid = FAIL;

  hid_t           ntype[10];
  hid_t           dtype = FAIL;
  hid_t           dtype_char = FAIL;
  hid_t           dtype1 = FAIL;

  long            ndims, strbufsize, nmaps, nflds, nattr;
  long            *off, *inc, *indx, offset, incr;

  hsize_t         *sizes, dimsize;
  hsize_t         dim[8], *dims, dim1[8], chunk_dim[8];
  hsize_t         n, nelem = 0;
    
  char            version[80] = {0};
  char            *dimname, *dimmap, *fieldlist; 
  char            dimlist[80], attrlist[80], dimlist1[80];

   int         level[ 5 ]      = { 0, 0, 0, 0, 0 };
   int         code            = 0;

  /* Open the Swath HDF-EOS File "Swath.h5" for reading only */
  /* ------------------------------------------------------- */
  swfid = HE5_SWopen("Swath.h5", H5F_ACC_RDONLY);
  if (swfid != FAIL)
    {
	  HE5_EHgetversion(swfid, version);
	  printf("HDF-EOS library version: \"%s\" \n", version);
	
	  /* Attach the swath "Swath1" */
	  /* ------------------------  */
	  SWid = HE5_SWattach(swfid, "Swath1");
	  if (SWid != FAIL)
		{
		  /* Inquire Dimensions */
		  /* ------------------ */
		  ndims = HE5_SWnentries(SWid, HE5_HDFE_NENTDIM, &strbufsize);
		  dims = (hsize_t *) calloc(ndims, sizeof(hsize_t));
		  dimname = (char *) calloc(strbufsize + 1, 1);
	    
		  ndims = HE5_SWinqdims(SWid, dimname, dims);

		  printf("Dimension list: %s\n", dimname);
		  for (i = 0; i < ndims; i++)
			printf("dim size: %li\n", (long)dims[i]);
	    
		  free(dims);
		  free(dimname);

		  /* Inquire Dimension Mappings */
		  /* -------------------------- */
		  nmaps = HE5_SWnentries(SWid, HE5_HDFE_NENTMAP, &strbufsize);
	    
		  off = (long *)calloc(nmaps, sizeof(long));
		  inc = (long *)calloc(nmaps, sizeof(long));
		  dimmap = (char *)calloc(strbufsize + 1, 1);
	    
		  nmaps = HE5_SWinqmaps(SWid, dimmap, off, inc);
		  printf("Dimension map: %s\n", dimmap);
		  for (i = 0; i < nmaps; i++)
			printf("offset increment: %li %li\n",
				   off[i], inc[i]);
		  free(off);
		  free(inc);
		  free(dimmap);


		  /* Inquire Indexed Dimension Mappings */
		  /* ---------------------------------- */
		  nmaps = HE5_SWnentries(SWid, HE5_HDFE_NENTIMAP, &strbufsize);
		  sizes = (hsize_t *) calloc(nmaps, sizeof(hsize_t));
		  dimmap = (char *) calloc(strbufsize + 1, 1);
		  nmaps = HE5_SWinqidxmaps(SWid, dimmap, sizes);

		  printf("Index Dimension map: %s\n", dimmap);
		  for (i = 0; i < nmaps; i++)
			printf("sizes: %lu\n", (unsigned long)sizes[i]);

		  free(sizes);
		  free(dimmap);


		  /* Inquire Geolocation Fields */
		  /* -------------------------- */
		  nflds = HE5_SWnentries(SWid, HE5_HDFE_NENTGFLD, &strbufsize);
		  rank = (int *)calloc(nflds, sizeof(int));
		  fieldlist = (char *) calloc(strbufsize + 1, 1);
		  nflds = HE5_SWinqgeofields(SWid, fieldlist, rank, ntype);

		  printf("geo fields: %s\n", fieldlist);
		  for (i = 0; i < nflds; i++)
			printf("Rank:  %d   Data type:  %ld\n", rank[i], (long) ntype[i]);

		  free(rank);
		  free(fieldlist);

		  /* Inquire Data Fields */
		  /* ------------------- */
		  nflds = HE5_SWnentries(SWid, HE5_HDFE_NENTDFLD, &strbufsize);
		  rank = (int *) calloc(nflds, sizeof(int));
		  fieldlist = (char *) calloc(strbufsize + 1, 1);
		  nflds = HE5_SWinqdatafields(SWid, fieldlist, rank, ntype);

		  printf("data fields: %s\n", fieldlist);
		  for (i = 0; i < nflds; i++)
			printf("Rank:  %d   Data type:  %ld\n", rank[i], (long) ntype[i]);

		  free(rank);
		  free(fieldlist);


		  /* Get info on "GeoTrack" dim */
		  /* -------------------------- */
		  dimsize = HE5_SWdiminfo(SWid, "GeoTrack");
		  printf("Size of GeoTrack: %lu\n", (unsigned long)dimsize);

                  dimsize = HE5_SWdiminfo(SWid, "Unlim");
                  printf("Size of Unlim: %li\n", (long)dimsize);

		  /* Get info on "GeoTrack/Res2tr" mapping */
		  /* ------------------------------------- */
		  status = HE5_SWmapinfo(SWid, "GeoTrack", "Res2tr", &offset, &incr);
		  printf("Mapping Offset: %li\n", offset);
		  printf("Mapping Increment: %li\n", incr);


		  /* Get info on "IndxTrack/Res2tr" indexed mapping */
		  /* ---------------------------------------------- */
		  dimsize = HE5_SWdiminfo(SWid, "IndxTrack");
		  indx = (long *) calloc(dimsize, sizeof(long));
		  n = HE5_SWidxmapinfo(SWid, "IndxTrack", "Res2tr", indx);
		  for (i = 0; i < n; i++)
			printf("Index Mapping Entry %d: %li\n", i+1, indx[i]);
		  free(indx);

		  /* Get info on "Longitude" Field */
		  /* ----------------------------- */
		  status = HE5_SWfieldinfo(SWid, "Longitude", &rk, dim, &dtype, dimlist, NULL);
		  printf("Longitude Rank: %d\n", rk);
		  printf("Longitude NumberType: %ld\n", (long) dtype);
		  printf("Longitude Dimension List: %s\n", dimlist);	    
		  for (i = 0; i < rk; i++)
			printf("Dimension %d: %lu\n",i+1,(unsigned long)dim[i]);

                  status = HE5_SWfieldinfo(SWid, "Test_string", &rk1, dim1, &dtype_char, dimlist1, NULL);
                  printf("Test_string Rank: %d\n", rk1);
                  printf("Test_string NumberType: %ld\n", (long) dtype_char);
                  printf("Test_string Dimension List: %s\n", dimlist1);
                  for (i = 0; i < rk1; i++)
                        printf("Dimension %d: %lu\n",i+1,(unsigned long)dim1[i]);

          dtype1 = FAIL;
		  /* Get info about Global Attributes */
		  /* -------------------------------- */
		  printf("Global Attribute:\n");
		  status = HE5_SWattrinfo(SWid,"GlobalAttribute",&dtype1, &nelem);
		  printf("\t\t Data type:          %ld\n", (long) dtype1);
		  printf("\t\t Number of elements: %lu \n", (unsigned long)nelem);    
 
                  nelem = 0;
                  status = HE5_SWattrinfo(SWid,"GLOBAL_CHAR_ATTR",&dtype1, &nelem);
                  printf("\t\t Data type:          %ld\n", (long) dtype1);
                  printf("\t\t The size of string: %lu \n", (unsigned long)nelem);

                  nelem = 0;
                  status = HE5_SWattrinfo(SWid,"GLOBAL_DOUBLE_ATTR",&dtype1, &nelem);
                  printf("\t\t Data type:          %ld\n", (long) dtype1);
                  printf("\t\t Number of elements: %lu \n", (unsigned long)nelem);

		  nelem = 0;
          dtype1 = FAIL;
		  /* Get info about Group Attributes */
		  /* ------------------------------- */
		  printf("Group Attribute:\n");
		  status = HE5_SWgrpattrinfo(SWid,"GroupAttribute",&dtype1,&nelem);
		  printf("\t\t Data type:          %ld\n", (long) dtype1);
		  printf("\t\t Number of elements: %lu \n", (unsigned long)nelem);    

		  nelem = 777;
          dtype1 = FAIL;
		  /* Get info about Local Attributes */
		  /* ------------------------------- */
		  printf("Local Attribute:\n");
		  status = HE5_SWlocattrinfo(SWid,"Density", "LocalAttribute_1",&dtype1,&nelem);
		  printf("\t\t Data type:          %ld\n", (long) dtype1);
		  printf("\t\t Number of elements: %lu \n", (unsigned long)nelem);    

		  printf("Local Attribute:\n");
		  status = HE5_SWlocattrinfo(SWid,"Longitude", "LocalAttribute_2",&dtype1,&nelem);
		  printf("\t\t Data type:          %ld\n", (long) dtype1);
		  printf("\t\t Number of elements: %lu \n", (unsigned long)nelem);    

                  nelem = 0;
                  status = HE5_SWlocattrinfo(SWid,"Time", "LOCAL_CHAR_ATTR",&dtype1,&nelem);
                  printf("\t\t Data type:          %ld\n", (long) dtype1);
                  printf("\t\t The size of string: %lu \n", (unsigned long)nelem);

		  /* Inquire Global Attributes */
		  /* ------------------------- */
		  printf("Global Attributes:\n");
		  nattr = HE5_SWinqattrs(SWid, NULL, &strbufsize);
		  printf("\t\t Number of attributes:             %li \n", nattr);
		  printf("\t\t String length of attribute list:  %li \n", strbufsize);
		  n = HE5_SWinqattrs(SWid, attrlist, &strbufsize);
		  printf("\t\t Attribute list:                   %s \n", attrlist);
           
		  /* Inquire Group Attributes */
		  /* ------------------------ */
		  strbufsize = 0;
		  printf("\n");
		  printf("Group Attributes:\n");
		  nattr = HE5_SWinqgrpattrs(SWid, NULL, &strbufsize);
		  printf("\t\t Number of attributes:             %li \n", nattr);
		  printf("\t\t String length of attribute list:  %li \n", strbufsize);
		  strcpy(attrlist,"");
		  nattr = HE5_SWinqgrpattrs(SWid, attrlist, &strbufsize);
		  printf("\t\t Attribute list:                   %s \n", attrlist);

		  /* Inquire Local Attributes */
		  /* ------------------------ */
		  strbufsize = 0;
		  printf("\n");
		  printf("Local Attributes:\n");
		  nattr = HE5_SWinqlocattrs(SWid, "Density", NULL, &strbufsize);
		  printf("\t\t Number of attributes:             %li \n", nattr);
		  printf("\t\t String length of attribute list:  %li \n", strbufsize);
		  strcpy(attrlist,"");
		  nattr = HE5_SWinqlocattrs(SWid, "Density", attrlist, &strbufsize);
		  printf("\t\t Attribute list:                   %s \n", attrlist);

		  nattr = HE5_SWinqlocattrs(SWid, "Longitude", NULL, &strbufsize);
		  printf("\t\t Number of attributes:             %li \n", nattr);
		  printf("\t\t String length of attribute list:  %li \n", strbufsize);
		  strcpy(attrlist,"");
		  nattr = HE5_SWinqlocattrs(SWid, "Longitude", attrlist, &strbufsize);
		  printf("\t\t Attribute list:                   %s \n", attrlist);

                  status = HE5_SWcompinfo(SWid,"Spectra",&code,level);
                  printf("\n");
                  printf("\t\t Compression scheme       Compression level\n");
                  printf("\t\t    %d,                      %d\n", code, level[0]);
 
                  status = HE5_SWchunkinfo(SWid,"Spectra",&chunk_rank,chunk_dim);
                  printf("\n");
                  printf("\t\t Spectra chunk rank: %d\n", chunk_rank);
                  for (i = 0; i < chunk_rank; i++)
                        printf("\t\t Spectra chunk dimension %d: %lu\n",i+1, (unsigned long)chunk_dim[i]);


		}
    }

  status = HE5_SWdetach(SWid);
  status = HE5_SWclose(swfid);

  return 0;
}