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
|
/*
----------------------------------------------------------------------------
| Copyright (C) 1999 Emergent IT Inc. and Raytheon Systems Company |
----------------------------------------------------------------------------
*/
#include <HE5_HdfEosDef.h>
#define DIMIN 100
#define DIMOUT 60
/*
* In this example we will (1) open the "Grid.h5" HDF-EOS file, (2) attach to
* the "UTMGrid", (3) read external data
*/
int main()
{
FILE *in_1, *in_2, *in_3;
herr_t status = FAIL;
int i;
int data_in_1[DIMIN];
int data_in_2[DIMIN];
int data_in_3[DIMIN];
int data_out[DIMOUT];
int nfiles = FAIL;
hid_t gdfid = FAIL;
hid_t GDid = FAIL;
size_t namelength = 48;
off_t offset[3];
char filelist[256];
hssize_t start[2];
hsize_t count[2];
hsize_t size[3];
/* Create the external data sets */
/* ----------------------------- */
for (i = 0; i < DIMIN; i++)
{
data_in_1[i] = 1000 + i + 1;
data_in_2[i] = 2000 + i + 1;
data_in_3[i] = 3000 + i + 1;
}
/* Open the external data files */
/* ---------------------------- */
in_1 = fopen("external_1g.data", "w");
in_2 = fopen("external_2g.data", "w");
in_3 = fopen("external_3g.data", "w");
/* Write data buffers to the external data files */
/* --------------------------------------------- */
fwrite(data_in_1, sizeof(int), DIMIN, in_1);
fwrite(data_in_2, sizeof(int), DIMIN, in_2);
fwrite(data_in_3, sizeof(int), DIMIN, in_3);
/* Close the external data files */
/* ----------------------------- */
fclose(in_1);
fclose(in_2);
fclose(in_3);
/*
* Open the HDF grid file, "Grid.h5".
*/
gdfid = HE5_GDopen("Grid.h5", H5F_ACC_RDWR);
if (gdfid != FAIL)
{
/*
* Attach the "UTMGrid".
*/
GDid = HE5_GDattach(gdfid, "UTMGrid");
if (GDid != FAIL)
{
/* Read the external data field */
/* ---------------------------- */
start[0] = 0;
count[0] = DIMOUT;
status = HE5_GDreadfield(GDid, "ExtData", start, NULL, count, data_out);
printf("Status returned by HE5_GDreadfield() : %d \n", status);
/* Display external data set */
/* ------------------------- */
printf(" \n");
for (i = 0; i < DIMOUT; i++)
printf("%d ", data_out[i]);
/* Get the number of external files */
/* -------------------------------- */
nfiles = HE5_GDgetextdata(GDid, "ExtData", namelength, filelist, offset, size);
printf(" \n");
printf(" \n");
printf("Number of external files returned by HE5_GDgetextdata() : %d \n", nfiles);
if (nfiles > 0)
{
printf(" \n");
printf("External files: \"%s\" \n", filelist);
printf(" \n");
printf("offsets: ");
for (i = 0; i < nfiles; i++)
printf("%d ", (int)offset[i]);
printf(" \n");
printf("sizes: ");
for (i = 0; i < nfiles; i++)
printf("%lu ", (unsigned long)size[i]);
printf(" \n");
printf(" \n");
}
}
}
/* Detach from the Grid */
/* -------------------- */
status = HE5_GDdetach(GDid);
printf("Status returned by HE5_GDdetach() : %d \n", status);
/* Close the file */
/* -------------- */
status = HE5_GDclose(gdfid);
printf("Status returned by HE5_GDclose() : %d \n", status);
return 0;
}
|