File: he5_sw_rdexternaldata.c

package info (click to toggle)
hdf-eos5 2%3A2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,692 kB
  • sloc: ansic: 92,051; fortran: 31,463; sh: 11,395; makefile: 492
file content (140 lines) | stat: -rwxr-xr-x 3,408 bytes parent folder | download | duplicates (9)
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
/*
 ---------------------------------------------------------------------------- 
 |    Copyright (C) 1999   Emergent IT Inc. and Raytheon Systems Company    |
 ----------------------------------------------------------------------------
 */



#include    <HE5_HdfEosDef.h>

#define  DIMIN    100
#define  DIMOUT   60

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           swfid  = FAIL;
  hid_t           SWid   = 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_1.data", "w");
  in_2 = fopen("external_2.data", "w");
  in_3 = fopen("external_3.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-EOS swath file, "Swath.h5" */
  /* --------------------------------------- */
  swfid = HE5_SWopen("Swath.h5", H5F_ACC_RDWR);
  if (swfid != FAIL)
	{
	  /* Attach the "Swath1" swath */
	  /* ------------------------- */
	  SWid = HE5_SWattach(swfid, "Swath1");
	  if (SWid != FAIL)
		{
		  /* Read the external data field */
		  /* ---------------------------- */
		  start[0] = 0;
		  count[0] = DIMOUT;
		  status = HE5_SWreadfield(SWid, "ExtData", start, NULL, count, data_out);
		  printf("Status returned by HE5_SWreadfield() :    %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_SWgetextdata(SWid, "ExtData", namelength, filelist, offset, size);
		  printf(" \n");
		  printf(" \n");
		  printf("Number of external files returned by HE5_SWgetextdata() :     %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 swath */
  /* --------------------- */
  status = HE5_SWdetach(SWid);
  printf("Status returned by HE5_SWdetach() :       %d \n", status);
  
  /* Close the file */
  /* -------------- */
  status = HE5_SWclose(swfid);
  printf("Status returned by HE5_SWclose() :        %d \n", status);

  return 0;
}