File: he5_gd_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 (80 lines) | stat: -rwxr-xr-x 2,238 bytes parent folder | download | duplicates (9)
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
/*
 ----------------------------------------------------------------------------
 |    Copyright (C) 1999   Emergent IT Inc. and Raytheon Systems Company    |
 ----------------------------------------------------------------------------
 */



#include      <HE5_HdfEosDef.h>


/*
 * In this example we will (1) open the "Grid.h5" HDF-EOS file, (2) attach to
 * the "UTMGrid", (3) read data from the "Vegetation" field. and (4) read 
 * global, group, and  local attributes.
 */


int main()
{
  herr_t          status = FAIL;

  int             i, j;
  int             grpattr[3] = {-9,-9,-9};         /* group attribute  */

  hid_t           gdfid = FAIL;
  hid_t           GDid  = FAIL;

  float           flt     = -999.;	               /* global attribute */
  float           attr[4] = {-9.9,-9.9,-9.9,-9.9}; /* local attribute  */
  float           veg[200][120];
      
  hssize_t        start[2] ={0, 0};
    
  hsize_t         edge[2] = {200, 100};

  /*
   * Open the HDF grid file, "Grid.h5".
   */
  gdfid = HE5_GDopen("Grid.h5", H5F_ACC_RDWR);
  if (gdfid != FAIL)
    {
	  /*
	   * Attach the "UTMGrid".
	   */
	  GDid = HE5_GDattach(gdfid, "UTMGrid");
	  if (GDid != FAIL)
		{
		  status = HE5_GDreadfield(GDid, "Vegetation", start, NULL, edge, veg);
		  printf("Status returned by HE5_GDreadfield() :    %d \n", status );
		  for (i = 0; i < 5; i++)
			for (j = 0; j < 10; j++)
			  printf("\t\t %f \n", veg[i][j]);
	  
		  status = HE5_GDreadattr(GDid, "GlobalAttribute", &flt);
		  printf("Status returned by HE5_GDreadattr() :     %d \n", status );
		  printf("\tGlobal attribute reads: \n");
		  printf("\t\t %f \n", flt);

		  status = HE5_GDreadgrpattr(GDid, "GroupAttribute", grpattr);
		  printf("Status returned by HE5_GDreadgrpattr() :  %d \n", status );
		  printf("\tGroup attribute reads: \n");
		  for (i = 0; i < 3; i++)
			printf("\t\t %d \n", grpattr[i]);

		  status = HE5_GDreadlocattr(GDid, "Vegetation","LocalAttribute", attr);
		  printf("Status returned by HE5_GDreadlocattr() :  %d \n", status );
		  printf("\tLocal attribute reads: \n");
		  for (i = 0; i < 4; i++)
			printf("\t\t %f \n", attr[i]);
		  
		}
    }

  status = HE5_GDdetach(GDid);
  status = HE5_GDclose(gdfid);

  return 0;
}