11 const char *vdata_name,
const char *class_name, int32_t n_flds,
12 char const *
const fldname[], int32_t
type[], int32_t noext, int32_t *aid) {
15 static int32_t prod_count = 0;
19 *vdata_id = VSattach(fileid, -1,
"w");
22 for (int32_t
i = 0;
i < n_flds;
i++) {
25 printf(
"Error defining \"%s\".\n", fldname[
i]);
31 strcpy(buffer, fldname[0]);
32 for (int32_t
i = 1;
i < n_flds;
i++) {
34 strcat(buffer, fldname[
i]);
36 status = VSsetfields(*vdata_id, buffer);
38 status = Vinsert(vgid, *vdata_id);
39 status = VSsetname(*vdata_id, vdata_name);
40 status = VSsetclass(*vdata_id, class_name);
42 VSsetblocksize(*vdata_id, 4096 * 6);
46 if (strcmp(class_name,
"DataSubordinate") == 0 && noext == 0) {
50 memset(buffer, 0,
sizeof (buffer));
51 status = VSwrite(*vdata_id, (uint8_t *) buffer, 1, FULL_INTERLACE);
53 *vdata_id = VSattach(fileid, VSfind(fileid, vdata_name),
"w");
58 Hfidinquire(fileid, &outname, &access, &attach);
62 char *cptr = strstr(buffer,
".main");
63 if (strlen(buffer) + buffer - cptr == 5)
66 sprintf(&buffer[strlen(buffer)],
".x%02d", prod_count);
70 sfile = fopen(buffer,
"w");
72 if (strrchr(outname,
'/') !=
NULL)
73 strcpy(buffer, strrchr(outname,
'/') + 1);
77 cptr = strstr(buffer,
".main");
78 if (strlen(buffer) + buffer - cptr == 5)
81 status = fwrite(buffer, 512, 1, sfile);
87 cptr = strstr(buffer,
".main");
88 if (strlen(buffer) + buffer - cptr == 5)
91 sprintf(&buffer[strlen(buffer)],
".x%02d", prod_count);
92 *aid = HXcreate(fileid, DFTAG_VS, (uint16_t) VSfind(fileid, vdata_name),
96 *vdata_id = VSattach(fileid, VSfind(fileid, vdata_name),
"w");
106 int32_t n_write = VSwrite(vdata_id, (
const uint8_t*)
data,
107 n_recs_to_write, FULL_INTERLACE);
109 if (n_write != n_recs_to_write) {
110 cout <<
"Error in VSwrite (write_vdata): "
111 << n_recs_to_write <<
" " << n_write << endl;
120 printf(
"The number of elements requested to be read is 0.\n");
124 int32_t binlist_offset[] = {0, 4, 6, 8, 12, 16, 20};
127 int32_t binlist_size[] = {4, 2, 2, 2, 4, 1, 4};
130 bytebuf = (uint8_t *) malloc(n_elem * 19);
134 records_read = VSread(vdata_id_binlist, bytebuf, n_elem, FULL_INTERLACE);
137 for (int32_t
j = 0;
j < n_elem;
j++) {
138 int binlist_idx =
j * 19;
139 for (
size_t i = 0;
i < 7;
i++) {
142 char *ptr = (
char *) &binList[
j] + binlist_offset[
i];
143 memcpy(ptr, &bytebuf[binlist_idx], binlist_size[
i]);
145 binlist_idx += binlist_size[
i];
149 memcpy(&bin, &bytebuf[
j * 19], 4);
153 memcpy((
char *) &binList[
j] + 24, &
lat, 4);
154 memcpy((
char *) &binList[
j] + 28, &
lon, 4);
165 printf(
"No elements are requested to be written in \"write_binList\".\n");
169 int32_t binlist_struct_offset[] = {0, 4, 6, 8, 12, 16, 20};
172 int32_t binlist_vdata_offset[] = {0, 4, 6, 8, 10, 14, 15};
175 int32_t binlist_size[] = {4, 2, 2, 2, 4, 1, 4};
178 bytebuf = (uint8_t *) malloc(n_elem * 19);
180 for (int32_t
j = 0;
j < n_elem;
j++) {
182 for (
size_t i = 0;
i < 7;
i++) {
183 char *ptr = (
char *) &binList[
j] + binlist_struct_offset[
i];
184 memcpy(&bytebuf[
j * 19 + binlist_vdata_offset[
i]], ptr,
188 int records_written =
189 VSwrite(vdata_id_binlist, bytebuf, n_elem, FULL_INTERLACE);
191 if (records_written != n_elem) {
192 cout <<
"Error in VSwrite (write_binList): "
193 << n_elem <<
" " << records_written << endl;
199 return records_written;
208 for (int32_t
j = 0;
j < n_elem;
j++) {
209 memcpy((
void *) &binListRec, &binList[
j],
sizeof (
binListStruct));
211 dta[0] =
data[
j] * binListRec.weights;
216 records_written = VSwrite(vdata_id_proddata, (
const uint8_t*) dta, 1,
219 if (records_written != 1) {
220 cout <<
"Error in VSwrite (write_prodData): "
221 << 1 <<
" " << records_written << endl;
230 char const *
const fldname3[],
231 int32_t in_vdata_id_proddata,
232 int32_t out_vdata_id_proddata) {
236 strcpy(buffer, fldname3[0]);
238 strcat(buffer, fldname3[1]);
239 intn
status = VSsetfields(in_vdata_id_proddata, buffer);
241 printf(
"Error setting fields: %s\n", buffer);
245 for (int32_t
j = 0;
j < n_elem;
j++) {
246 VSseek(in_vdata_id_proddata, binsToCopy[
j]);
247 int records_read = VSread(in_vdata_id_proddata,
248 (uint8_t *) & dta[0], 1, FULL_INTERLACE);
250 int records_written = VSwrite(out_vdata_id_proddata,
251 (
const uint8_t*) dta, 1, FULL_INTERLACE);
253 if (records_read != records_written) {
254 cout <<
"Error in copy: "
255 << records_read <<
" " << records_written << endl;
263 hid_t *type_id,
size_t typesize, int32_t n_flds,
264 char const *
const fldname[],
size_t offset[], hid_t
type[],
265 hid_t *filespace, hid_t dataspace) {
268 *type_id = H5Tcreate(H5T_COMPOUND, typesize);
269 for (int32_t
i = 0;
i < n_flds;
i++) {
272 cout <<
"H5Tinsert error for: " << dataset_name
273 <<
" (field: " << fldname[
i] <<
")." << endl;
278 hid_t cparms = H5Pcreate(H5P_DATASET_CREATE);
280 hsize_t chuck_dims[1] = {1};
281 status = H5Pset_chunk(cparms, 1, chuck_dims);
282 *dataset_id = H5Dcreate1(group_id, dataset_name, *type_id, dataspace,
284 if (*dataset_id < 0) {
285 cout <<
"Cannot create dataset for: " << dataset_name <<
"." << endl;
289 status = H5Pclose(cparms);
291 *filespace = H5Dget_space(*dataset_id);
292 if (*filespace < 0) {
293 cout <<
"Cannot get filespace for: " << dataset_name <<
"." << endl;
297 cout <<
"\"" << dataset_name <<
"\"" <<
" successfully created." << endl;
298 cout <<
"Dataset id: " << *dataset_id << endl;
299 cout <<
"Datatype id: " << *type_id << endl;
300 cout <<
"Filespace id: " << *filespace << endl << endl;