File: he5_sw_wrunlimfld.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 (205 lines) | stat: -rwxr-xr-x 5,723 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 ----------------------------------------------------------------------------
 |    Copyright (C) 1999   Emergent IT Inc. and Raytheon Systems Company    |
 ----------------------------------------------------------------------------
 */


#include <HE5_HdfEosDef.h>

/* In this program we (1) open the "Swath.h5" HDF-EOS file, (2) attach to  */
/* the "Swath1" swath, and (3) write data to the "Longitude", "Latitude",  */
/*      and (appendable) "Spectra" fields                                  */
/* ----------------------------------------------------------------------- */


int main()
{
  herr_t          status = FAIL;

  int             i, j, k;
  int             track, xtrack;
  int             rank = FAIL;

  hid_t           swfid = FAIL;
  hid_t           SWid  = FAIL;

  hid_t     *ntype;

  hssize_t        start[3] = {0, 0, 0};
    
  hsize_t         count[3];
  hsize_t         dims[8] = {0, 0, 0, 0, 0, 0, 0, 0};

  long            attr[4] = {3, 5, 7, 11};

  float           lng[20][10], latcnt;  
  float           lat[20][10], loncnt;

  double          plane[15][40][20];
  double          tme[20];

  char            dimlist[80];
  char            maxdimlist[80];   

  hvl_t           buffer[4];

  size_t          datasize;


  /* Populate lon/lat data arrays */
  /* ---------------------------- */
  latcnt = 1.;
  loncnt = 1.;
  track  = 0;
  xtrack = 0;
 
  while(track < 20) {
	while(xtrack < 10) {
	  lat[track][xtrack] = latcnt;
	  lng[track][xtrack] = loncnt;
	  loncnt = loncnt + 1.;
	  xtrack++;
	}
	latcnt = latcnt + 1.;
	loncnt = 1.;
	track++;
	xtrack = 0;
  }
    

  /* Popolate spectra data arrays */
  /* ---------------------------- */
  for (i = 0; i < 15; i++){
	for (j = 0; j < 40; j++)
	  for (k = 0; k < 20; k++)
		plane[i][j][k] = (double)(j*100 + i);
  }


  /* Allocate memory for and populate data buffer */
  /* -------------------------------------------- */
  datasize = 0;
  for (i = 0; i < 4; i++)
	{
	  buffer[i].p = (hvl_t *)calloc( 25 *(i+1), sizeof(unsigned int));
	  buffer[i].len  =  25 * (i+1);
	  /* calculate the data buffer size (bytes) */
	  datasize += buffer[i].len * sizeof(unsigned int);
	  for ( j = 0; j < 25 * (i+1); j++)
		((unsigned int *)buffer[i].p)[j] = (i+1)*1000 + j;
	}


  /* Open the HDF 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)
		{
		  count[0] = 20;
		  count[1] = 10;

		  /* Write "Longitute" field */
		  /* ----------------------- */
		  status = HE5_SWwritefield(SWid, "Longitude", start, NULL, count, lng);
		  printf("status returned by HE5_SWwritefield(\"Longitude\"):         %d\n", status);
	    
		  /* Write "Latitude" field */
		  /* ---------------------- */
		  status = HE5_SWwritefield(SWid, "Latitude", start, NULL, count, lat);
		  printf("status returned by HE5_SWwritefield(\"Latitude\"):          %d\n", status);

		  /*  Write "Time" field */
		  /* ------------------- */
		  for (i = 0; i < 20; i++) 
			tme[i] = 34574087.3 + 84893.2*i;

		  count[0] = 20;
		  status = HE5_SWwritefield(SWid, "Time", start, NULL, count, tme);
		  printf("status returned by HE5_SWwritefield(\"Time\"):              %d\n", status);

		  /*  Write "Spectra" field  1st time */
		  /* -------------------------------- */

		  count[0] = 15;  
		  count[1] = 40;  
		  count[2] = 20;

		  status = HE5_SWwritefield(SWid, "Spectra", start, NULL, count, plane);
		  printf("status returned by HE5_SWwritefield(\"Spectra\"):           %d\n", status);

		  /* Retrieve information about "Spectra" field */
		  /* ------------------------------------------ */

		  ntype = (hid_t *)calloc(3,sizeof(hid_t));

		  status = HE5_SWfieldinfo(SWid, "Spectra", &rank, dims, ntype, dimlist, maxdimlist);
		  printf("Number of elements after first write: \n");
		  for ( i = 0; i < rank; i++)
			printf("\t\t %lu\n",(unsigned long)dims[i]);

		  printf("DimList string:        %s \n", dimlist);
		  printf("MaxdimList string:     %s \n", maxdimlist);

		  /*  Write Spectra Field  2d time */
		  /* ----------------------------- */

		  start[0] = 10;  
		  start[1] = 50;  
		  start[2] = 30;

		  count[0] = 15;  
		  count[1] = 40;  
		  count[2] = 20;

		  status = HE5_SWwritefield(SWid, "Spectra", start, NULL, count, plane);
		  printf("status returned by HE5_SWwritefield(\"Spectra\"):           %d\n", status);

		  /* Retrieve information about "Spectra" field */
		  /* ------------------------------------------ */

		  dims[0] = 0;  
		  dims[1] = 0; 
		  dims[2] = 0;
		  status = HE5_SWfieldinfo(SWid, "Spectra", &rank, dims, ntype, dimlist, maxdimlist);
		  printf("Number of elements after second write: \n");
		  for ( i = 0; i < rank; i++)
			{
			  printf("\t\t %lu\n",(unsigned long)dims[i]);
			}
		  printf("DimList string:        %s \n", dimlist);
		  printf("MaxdimList string:     %s \n", maxdimlist);            

		  free(ntype);

		  /* Write data to the profile */
		  /* ------------------------- */
		  start[0] = 0;  count[0] = 4;
		  status = HE5_PRwrite(SWid, "Profile-2000", start, NULL, count, datasize, buffer);
		  printf("Status returned by HE5_PRwrite(\"Profile-2000\"):           %d \n", status);
   
		  /* Write User-defined Attribute */
		  /* ---------------------------- */
		  count[0] = 4;
		  status = HE5_SWwriteattr(SWid, "TestAttr", H5T_NATIVE_INT, count, attr);
		  printf("status returned by HE5_SWwriteattr(\"TestAttr\"):           %d\n", status);
	    
		}
    }

  status = HE5_SWdetach(SWid);
  status = HE5_SWclose(swfid);

  return 0;
}