5
* In this example we will (1) open the "GridFile" HDF file, (2) attach to
6
* the "Grid1" grid, and (3) set dimension scale for a dimension in all filed of a grid.
14
int32 gdfid, GDid1, GDid2, GDid3;
18
int32 data[10]={3,6,9,12,15,18,23,26,29,32};
19
int32 bands[10]={12,14,18};
25
* We first open the HDF grid file, "GridFile.hdf". Because this file
26
* already exist and we wish to write to it, we use the DFACC_RDWR access
27
* code in the open statement. The GDopen routine returns the grid file
28
* id, gdfid, which is used to identify the file in subsequent routines.
31
gdfid = GDopen("GridFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_RDWR);
35
* If the grid file cannot be found, GDopen will return -1 for the file
36
* handle (gdfid). We there check that this is not the case before
37
* proceeding with the other routines.
39
* The GDattach routine returns the handle to the existing grid "Grid1",
40
* GDid. If the grid is not found, GDattach returns -1 for the handle.
45
/* the field Pollution has Time,YDim,XDim dimensions.
46
see SetupGrid.c and DefineGDflds.c
52
GDid1 = GDattach(gdfid, "UTMGrid");
55
printf("\t\tError: Cannot attach to grid \"UTMGrid\"\n");
63
status = GDdefdimscale(GDid1, "XDim", xdim, DFNT_FLOAT64, NULL);
66
printf("\t\tError: Cannot set Dimension Scale for XDim dimemnsion in field \"Pollution\"\n");
72
status = GDdefdimscale(GDid1, "Time", ntime, DFNT_INT32, data);
75
printf("\t\tError: Cannot set Dimension Scale for Time dimemnsion in field \"Pollution\"\n");
81
strcpy(label, "X Dimension");
82
strcpy(unit, "meters");
83
strcpy(format, "F7.2");
85
status = GDdefdimstrs(GDid1, "XDim", label, unit, format);
88
printf("\t\tError: Cannot set Dimension Scale strs for XDim dimemnsion in field \"Pollution\"\n");
94
strcpy(label, "Time Dim");
98
status = GDdefdimstrs(GDid1, "Time", label, unit, format);
101
printf("\t\tError: Cannot set Dimension Scale strs for Time dimemnsion in field \"Pollution\"\n");
109
/* the field Spectra has Bands,YDim,XDim dimensions.
110
see SetupGrid.c and DefineGDflds.c
113
Bands dim is set to 3
116
GDid2 = GDattach(gdfid, "PolarGrid");
119
printf("\t\tError: Cannot attach to grid \"PolarGrid\"\n");
127
status = GDdefdimscale(GDid2, "YDim", ydim, DFNT_FLOAT64, NULL);
130
printf("\t\tError: Cannot set Dimension Scale for YDim dimemnsion in field \"Spectra\"\n");
137
status = GDdefdimscale(GDid2, "Bands", nbands, DFNT_INT32, bands);
140
printf("\t\tError: Cannot set Dimension Scale for Bands dimemnsion in field \"Spectra\"\n");
147
strcpy(label, "Y Dimension");
148
strcpy(unit, "meters");
149
strcpy(format, "F7.2");
151
status = GDdefdimstrs(GDid2, "YDim", label, unit, format);
154
printf("\t\tError: Cannot set Dimension Scale strs for YDim dimemnsion in field \"Spectra\"\n");
160
strcpy(label, "Bands");
161
strcpy(unit, "None");
162
strcpy(format, "I2");
164
status = GDdefdimstrs(GDid2, "Bands", label, unit, format);
167
printf("\t\tError: Cannot set Dimension Scale strs for Bands dimemnsion in field \"Spectra\"\n");
177
/* the field GeoSpectra has YDim,XDim dimensions.
178
see SetupGrid.c and DefineGDflds.c
181
Bands dim is set to 3
187
GDid3 = GDattach(gdfid, "GEOGrid");
190
printf("\t\tError: Cannot attach to grid \"GEOGrid\"\n");
194
status = GDdefdimscale(GDid3, "YDim", ydim, DFNT_FLOAT64, NULL);
197
printf("\t\tError: Cannot set Dimension Scale for YDim dimemnsion in field \"GeoSpectra\"\n");
203
strcpy(label, "Y Dimension");
204
strcpy(unit, "Decimal Degrees");
205
strcpy(format, "F7.2");
207
status = GDdefdimstrs(GDid3, "YDim", label, unit, format);
210
printf("\t\tError: Cannot set Dimension Scale strs for YDim dimemnsion in field \"GeoSpectra\"\n");