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
|
#include "hdf.h"
#include "HdfEosDef.h"
/*
* In this example we will (1) open the "SwathFile" HDF file, (2) attach to
* the "UTMSwath", and (3) read data from the "Vegetation" field.
*/
main()
{
intn i, j, status;
int32 swfid, SWid, regionID, size, periodID;
int32 firstXtrk, LastXtrk, dims[8], rank, ntype;
float64 cornerlon[2], cornerlat[2];
float64 *datbuf;
/*
* Open the HDF swath file, "SwathFile.hdf".
*/
swfid = SWopen("SwathFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_RDWR);
if (swfid != -1)
{
SWid = SWattach(swfid, "Swath1");
if (SWid != -1)
{
cornerlon[0] = 3.;
cornerlat[0] = 5.;
cornerlon[1] = 7.;
cornerlat[1] = 12.;
regionID = SWdefboxregion(SWid, cornerlon, cornerlat,
HDFE_MIDPOINT);
if (regionID == -1)
{
printf("\t\tError: Cannot define subsetting region for swath \"Swath1\"\n");
return -1;
}
status = SWregioninfo(SWid, regionID, "Longitude", &ntype,
&rank, dims, &size);
if (status == -1)
{
printf("\t\tError: Cannot get region info for field \"Spectra\" of swath \"Swath1\"\n");
return -1;
}
status = SWregioninfo(SWid, regionID, "Spectra", &ntype,
&rank, dims, &size);
if (status == -1)
{
printf("\t\tError: Cannot get region info for field \"Spectra\" of swath \"Swath1\"\n");
return -1;
}
datbuf = (float64 *) malloc(size);
status = SWextractregion(SWid, regionID, "Spectra",
HDFE_INTERNAL, datbuf);
if (status == -1)
{
printf("\t\tError: Cannot extract region for field \"Spectra\" of swath \"Swath1\"\n");
return -1;
}
free(datbuf);
/* Time Subsetting */
periodID = SWdeftimeperiod(SWid, 35232487.2, 36609898.1,
HDFE_MIDPOINT);
if (periodID == -1)
{
printf("\t\tError: Cannot define time period for swath \"Swath1\"\n");
return -1;
}
status = SWperiodinfo(SWid, periodID, "Time", &ntype,
&rank, dims, &size);
if (status == -1)
{
printf("\t\tError: Cannot get period info for swath \"Swath1\"\n");
return -1;
}
datbuf = (float64 *) malloc(size);
status = SWextractperiod(SWid, periodID, "Time",
HDFE_INTERNAL, datbuf);
if (status == -1)
{
printf("\t\tError: Cannot extract period for swath \"Swath1\"\n");
return -1;
}
free(datbuf);
}
}
SWdetach(SWid);
SWclose(swfid);
return 0;
}
|