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
|
#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 swath fields.
*/
main()
{
intn status, i;
int32 swfid, SWid, ndims, nmaps, rk, nt, dim[8], nflds;
int32 *dims, *off, *inc, *indx, *rank, *ntype;
int32 n, strbufsize, dimsize, offset, incr, *sizes;
char *dimname, *dimmap, *fieldlist, dimlist[80];
/*
* Open the Swath File for read only access
*/
swfid = SWopen("SwathFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_READ);
if (swfid == -1)
{
printf("\t\tError: Cannot open file \"SwathFile.hdf\"\n");
return -1;
}
if (swfid != -1)
{
/* Attach the swath */
SWid = SWattach(swfid, "Swath1");
if (SWid == -1)
{
printf("\t\tError: Cannot attach swath \"Swath1\"\n");
return -1;
}
if (SWid != -1)
{
/* Inquire Dimensions */
ndims = SWnentries(SWid, HDFE_NENTDIM, &strbufsize);
if (ndims == -1)
{
printf("\t\tError: Cannot get number of dims for swath \"Swath1\"\n");
return -1;
}
dims = (int32 *) calloc(ndims, 4);
dimname = (char *) calloc(strbufsize + 1, 1);
ndims = SWinqdims(SWid, dimname, dims);
if (ndims == -1)
{
printf("\t\tError: Cannot get dims for swath \"Swath1\"\n");
return -1;
}
printf("Dimension list: %s\n", dimname);
for (i = 0; i < ndims; i++)
printf("dim size: %d\n", dims[i]);
free(dims);
free(dimname);
/* Inquire Dimension Mappings */
nmaps = SWnentries(SWid, HDFE_NENTMAP, &strbufsize);
if (nmaps == -1)
{
printf("\t\tError: Cannot get number of Dimension mappings for \"Swath1\"\n");
return -1;
}
off = (int32 *) calloc(nmaps, 4);
inc = (int32 *) calloc(nmaps, 4);
dimmap = (char *) calloc(strbufsize + 1, 1);
nmaps = SWinqmaps(SWid, dimmap, off, inc);
if (nmaps == -1)
{
printf("\t\tError: Cannot get Dimension mappings for \"Swath1\"\n");
return -1;
}
printf("Dimension map: %s\n", dimmap);
for (i = 0; i < nmaps; i++)
printf("offset increment: %d %d\n",
off[i], inc[i]);
free(off);
free(inc);
free(dimmap);
/* Inquire Indexed Dimension Mappings */
nmaps = SWnentries(SWid, HDFE_NENTIMAP, &strbufsize);
if (nmaps == -1)
{
printf("\t\tError: Cannot get number of Indexed mappings for \"Swath1\"\n");
return -1;
}
sizes = (int32 *) calloc(nmaps, 4);
dimmap = (char *) calloc(strbufsize + 1, 1);
nmaps = SWinqidxmaps(SWid, dimmap, sizes);
if (nmaps == -1)
{
printf("\t\tError: Cannot get Indexed mappings for \"Swath1\"\n");
return -1;
}
printf("Index Dimension map: %s\n", dimmap);
for (i = 0; i < nmaps; i++)
printf("sizes: %d\n", sizes[i]);
free(sizes);
free(dimmap);
/* Inquire Geolocation Fields */
nflds = SWnentries(SWid, HDFE_NENTGFLD, &strbufsize);
if (nflds == -1)
{
printf("\t\tError: Cannot get number of geo fields for swath \"Swath1\"\n");
return -1;
}
rank = (int32 *) calloc(nflds, 4);
ntype = (int32 *) calloc(nflds, 4);
fieldlist = (char *) calloc(strbufsize + 1, 1);
nflds = SWinqgeofields(SWid, fieldlist, rank, ntype);
if (nflds == -1)
{
printf("\t\tError: Cannot get number of geo fields for swath \"Swath1\"\n");
return -1;
}
printf("geo fields: %s\n", fieldlist);
for (i = 0; i < nflds; i++)
printf("rank type: %d %d\n", rank[i], ntype[i]);
free(rank);
free(ntype);
free(fieldlist);
/* Inquire Data Fields */
nflds = SWnentries(SWid, HDFE_NENTDFLD, &strbufsize);
if (nflds == -1)
{
printf("\t\tError: Cannot get number of data fields for swath \"Swath1\"\n");
return -1;
}
rank = (int32 *) calloc(nflds, 4);
ntype = (int32 *) calloc(nflds, 4);
fieldlist = (char *) calloc(strbufsize + 1, 1);
nflds = SWinqdatafields(SWid, fieldlist, rank, ntype);
if (nflds == -1)
{
printf("\t\tError: Cannot get number of data fields for swath \"Swath1\"\n");
return -1;
}
printf("data fields: %s\n", fieldlist);
for (i = 0; i < nflds; i++)
printf("rank type: %d %d\n", rank[i], ntype[i]);
free(rank);
free(ntype);
free(fieldlist);
/* Get info on "GeoTrack" dim */
dimsize = SWdiminfo(SWid, "GeoTrack");
if (dimsize == -1)
{
printf("\t\tError: Cannot get size for dimension \"GeoTrack\"\n");
return -1;
}
printf("Size of GeoTrack: %d\n", dimsize);
/* Get info on "GeoTrack/Res2tr" mapping */
status = SWmapinfo(SWid, "GeoTrack", "Res2tr", &offset, &incr);
if (status == -1)
{
printf("\t\tError: Cannot get map info between \"GeoTrack\" and \"Res2tr\"\n");
return -1;
}
printf("Mapping Offset: %d\n", offset);
printf("Mapping Increment: %d\n", incr);
/* Get info on "IndxTrack/Res2tr" indexed mapping */
dimsize = SWdiminfo(SWid, "IndxTrack");
if (dimsize == -1)
{
printf("\t\tError: Cannot get size for dimension \"IndxTrack\"\n");
return -1;
}
indx = (int32 *) calloc(dimsize, 4);
n = SWidxmapinfo(SWid, "IndxTrack", "Res2tr", indx);
if (n == -1)
{
printf("\t\tError: Cannot get index map info between \"IndxTrack\" and \"Res2tr\"\n");
return -1;
}
for (i = 0; i < n; i++)
printf("Index Mapping Entry %d: %d\n", i+1, indx[i]);
free(indx);
/* Get info on "Longitude" Field */
status = SWfieldinfo(SWid, "Longitude", &rk, dim, &nt, dimlist);
if (status == -1)
{
printf("\t\tError: Cannot get field info for field \"Longitude\"\n");
return -1;
}
printf("Longitude Rank: %d\n", rk);
printf("Longitude NumberType: %d\n", nt);
printf("Longitude Dimension List: %s\n", dimlist);
for (i=0; i<rk; i++)
printf("Dimension %d: %d\n",i+1,dim[i]);
}
}
status = SWdetach(SWid);
if (status == -1)
{
printf("\t\tError: Cannot detach SWid\n");
return -1;
}
status = SWclose(swfid);
if (status == -1)
{
printf("\t\tError: Cannot close hdf file.\n");
return -1;
}
return 0;
}
|