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
|
#include "hdf.h"
/*
* In this example we will (1) open the "GridFile" HDF file, (2) attach to
* the "UTMGrid", and (3) write data to the "Vegetation" field. We will
* then attach to the "PolarGrid" and write to the "Temperature" field.
*/
main()
{
intn i, j, status;
int32 gdfid, GDid,start[3],stride[3],edge[3];
float32 f32=1.0;
float32 veg[200][120], temp[100][100];
/* Fill veg array */
for (i=0; i<200;i++)
for (j=0; j<120; j++)
veg[i][j] = 10+i;
/* Fill temp array */
for (i=0; i<100;i++)
for (j=0; j<100; j++)
temp[i][j] = 100*i+j;
/*
* Open the HDF grid file, "GridFile.hdf".
*/
gdfid = GDopen("GridFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_RDWR);
if (gdfid != -1)
{
/*
* Attach the "UTMGrid".
*/
GDid = GDattach(gdfid, "UTMGrid");
if (GDid != -1)
{
status = GDwritefield(GDid, "Vegetation",
NULL, NULL, NULL, veg);
if (status == -1)
{
printf("\t\tError: Cannot write field \"Vegetation\"\n");
return -1;
}
/*
* It will always fail
status = GDwritefield(GDid, "Vegetat",
NULL, NULL, NULL, veg);
if (status == -1)
{
printf("\t\tError: Cannot write field \"Vegetat\"\n");
printf("\t\tField \"Vegetat\" has not been defined.\n");
}
*/
status = GDwriteattr(GDid, "float32", DFNT_FLOAT32, 1, &f32);
if (status == -1)
{
printf("\t\tError: Cannot write attribute \"float32\"\n");
return -1;
}
}
GDdetach(GDid);
GDid = GDattach(gdfid, "PolarGrid");
if (GDid != -1)
{
status = GDwritefield(GDid, "Temperature",
NULL, NULL, NULL, temp);
if (status == -1)
{
printf("\t\tError: Cannot write field \"Temperature\"\n");
return -1;
}
}
GDdetach(GDid);
}
GDclose(gdfid);
return 0;
}
|