/usr/share/doc/libhdfeos-dev/examples/ReadFields.c is in libhdfeos-dev 2.17v1.00.dfsg.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #include "hdf.h"
/*
* In this example we will (1) open the "SwathFile" HDF file, (2) attach to
* the "Swath1" swath, and (3) read data from the "Longitude" field.
*
* Unlike the WriteField routine, we will read the field all at once.
*/
main()
{
intn status, i, j, k, start[2],stride[2],count[2];
int32 swfid, SWid, attr[4];
float32 lng[20][10];
/* Allocate space for the longitude and spectral data */
/*
* Open the HDF swath file, "SwathFile.hdf".
*/
swfid = SWopen("SwathFile.hdf", DFACC_READ);
if (swfid == -1)
{
printf("\t\tError: Cannot open file \"SwathFile.hdf\"\n");
return -1;
}
if (swfid != -1)
{
/*
* Attach the "Swath1" swath.
*/
SWid = SWattach(swfid, "Swath1");
if (SWid == -1)
{
printf("\t\tError: Cannot attach swath \"Swath1\"\n");
return -1;
}
if (SWid != -1)
{
/* Read the entire longitude field */
status = SWreadfield(SWid, "Longitude", NULL, NULL, NULL, lng);
if (status == -1)
{
printf("\t\tError: Cannot read field \"Longitude\"\n");
return -1;
}
/* Print field */
for (i = 0; i < 20; i++)
for (j = 0; j < 10; j++)
printf("i j Longitude: %d %d %f\n",
i, j, lng[i][j]);
/* Read User Attribute */
status = SWreadattr(SWid, "TestAttr", attr);
if (status == -1)
{
printf("\t\tError: Cannot read attribute \"TestAttr\"\n");
return -1;
}
for (i=0;i<4;i++)
printf("Attribute Entry %d: %d\n",i+1,attr[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;
}
HEprint(stdout,0);
return 0;
}
|