File: InquireGrid.c

package info (click to toggle)
hdf-eos4 3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,960 kB
  • sloc: ansic: 43,570; sh: 11,324; fortran: 9,649; makefile: 261
file content (208 lines) | stat: -rw-r--r-- 5,410 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
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
#include "hdf.h"
#include "HdfEosDef.h"

/*
 * In this example we will retrieve (1) information about the dimensions,
 * (2) the dimension mappings (geolocation relations), and (3) the grid
 * fields.
 */


main()
{

    intn            status, i;
    int32           gdfid, GDid1, ndim, nmap, nfld, rk, nt, nflds;
    int32           dims[32], rank[32], ntype[32];
    int32           n, strbufsize, sizes[16], GDid2;
    int32           xdimsize, ydimsize, dimsize, projcode, zonecode;
    int32           spherecode;
    
    float64         upleftpt[2], lowrightpt[2], projparm[16];
    
    char            dimname[1024], fieldlist[1024];


    /*
     * Open the Grid File for read only access
     */

    gdfid = GDopen("GridFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_READ);

    
    if (gdfid != -1)
    {

	/* Attach the grid */

	GDid1 = GDattach(gdfid, "UTMGrid");
	if (GDid1 == -1)
	  {
	    printf("\t\tError: Cannot attach grid \"UTMGrid\"\n");
	    return -1;
	  }
	GDid2 = GDattach(gdfid, "PolarGrid");
	if (GDid1 == -1)
	  {
	    printf("\t\tError: Cannot attach grid \"PolarGrid\"\n");
	    return -1;
	  }
	ndim = GDinqdims(GDid1, dimname, dims);
	if (ndim == -1)
	  {
	    printf("\t\tError: Cannot get number of dims for grid \"UTMGrid\"\n");
	    return -1;
	  }
	printf("Dimension list (UTMGrid): %s\n", dimname);
	for (i=0;i<ndim;i++) printf("dim size: %d\n", dims[i]);

	ndim = GDinqdims(GDid2, dimname, dims);
	if (ndim == -1)
	  {
	    printf("\t\tError: Cannot get number of dims for grid \"PolarGrid\"\n");
	    return -1;
	  }
	printf("Dimension list (PolarGrid): %s\n", dimname);
	for (i=0;i<ndim;i++) printf("dim size: %d\n", dims[i]);


	dimsize = GDdiminfo(GDid1, "Time");
	if (dimsize == -1)
	  {
	    printf("\t\tError: Cannot get dim info for \"Time\"\n");
	    return -1;
	  }
	printf("Size of \"Time\" Array: %d\n", dimsize);

	dimsize = GDdiminfo(GDid2, "Bands");
	if (dimsize == -1)
	  {
	    printf("\t\tError: Cannot get dim info for \"Bands\"\n");
	    return -1;
	  }
	printf("Size of \"Bands\" Array: %d\n", dimsize);


	
	status = GDgridinfo(GDid1, &xdimsize, &ydimsize,
			    upleftpt, lowrightpt);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot get grid info for \"UTMGrid\"\n");
	    return -1;
	  }
	printf("X dim size, Y dim size (UTMGrid): %d %d\n", 
	       xdimsize, ydimsize);
	printf("Up left pt (UTMGrid): %lf %lf\n", 
	       upleftpt[0], upleftpt[1]);
	printf("Low right pt (UTMGrid): %lf %lf\n", 
	       lowrightpt[0], lowrightpt[1]);

	status = GDgridinfo(GDid2, &xdimsize, &ydimsize,
			    upleftpt, lowrightpt);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot get grid info for \"PolarGrid\"\n");
	    return -1;
	  }
	printf("X dim size, Y dim size (PolarGrid): %d %d\n", 
	       xdimsize, ydimsize);
	printf("Up left pt (PolarGrid): %lf %lf\n", 
	       upleftpt[0], upleftpt[1]);
	printf("Low right pt (PolarGrid): %lf %lf\n", 
	       lowrightpt[0], lowrightpt[1]);
	
	       
	status = GDprojinfo(GDid1, &projcode, &zonecode,
			    &spherecode, NULL);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot get projection info for \"UTMGrid\"\n");
	    return -1;
	  }
	printf("projcode , zonecode (UTMGrid): %d %d\n", projcode, zonecode);
	printf("spherecode (UTMGrid): %d\n", spherecode);	

	
	status = GDprojinfo(GDid2, &projcode, NULL,
			    &spherecode, projparm);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot get projection info for \"PolarGrid\"\n");
	    return -1;
	  }
	printf("projcode (PolarGrid): %d\n", projcode);	
	printf("spherecode (PolarGrid): %d\n", spherecode);	
	for (i=0; i<13; i++)
	    printf("Projection Parameter: %d %lf\n",i,projparm[i]);
	
	nflds = GDinqfields(GDid1, fieldlist, rank, ntype);
	if (nflds == -1)
	  {
	    printf("\t\tError: Cannot inquire field info for \"UTMGrid\"\n");
	    return -1;
	  }
	if (nflds != 0)
	{
	    printf("Data fields (UTMGrid): %s\n", fieldlist);
	    for (i=0;i<nflds;i++)
		printf("rank type: %d %d\n",rank[i],ntype[i]);
	}

	nflds = GDinqfields(GDid2, fieldlist, rank, ntype);
	if (nflds == -1)
	  {
	    printf("\t\tError: Cannot inquire field info for \"PolarGrid\"\n");
	    return -1;
	  }
	if (nflds != 0)
	{
	    printf("Data fields (PolarGrid): %s\n", fieldlist);
	    for (i=0;i<nflds;i++)
		printf("rank type: %d %d\n",rank[i],ntype[i]);
	}
	
	
	status = GDfieldinfo(GDid2, "Spectra", rank, 
			     dims, ntype, dimname);
	if (nflds == -1)
	  {
	    printf("\t\tError: Cannot get field info for field \"Spectra\"\n");
	    return -1;
	  }
	printf("Spectra rank dims: %d\n",rank[0]);
	for (i=0; i<rank[0]; i++)
	    printf("Spectra dims: %d %d\n",i,dims[i]);
	printf("Spectra dims: %s\n", dimname);
	
	
	n = GDnentries(GDid1, HDFE_NENTDIM, &strbufsize);
	if (n == -1)
	  {
	    printf("\t\tError: Cannot get dim entries info for field \"UTMGrid\"\n");
	    return -1;
	  }
	printf("Number of dimension entries (UTMGrid): %d\n", n);
	printf("Length of Dimension List (UTMGrid): %d\n", strbufsize);
	
	n = GDnentries(GDid1, HDFE_NENTDFLD, &strbufsize);
	if (n == -1)
	  {
	    printf("\t\tError: Cannot get dim entries info for field \"PolarGrid\"\n");
	    return -1;
	  }
	printf("Number of data fields (UTMGrid): %d\n", n);
	printf("Length of Field List (UTMGrid): %d\n", strbufsize);
	
    }
    GDdetach(GDid1);
    GDdetach(GDid2);
    GDclose(gdfid);

    return 0;
}