11 int32
wr_vdata(
char *outname, int32 fileid_w, int32 vgid,
char *
name,
12 char *class1, int32 n_flds, int32 n_recs_to_write,
13 char *fldname[], int32
type[], int32 noext, uint8 *
data,
20 static int32 prod_count = 0;
22 static int32 n_vdata_open = 0;
26 static char empty[8] = {
"_EMPTY_"};
35 for (
j = 0;
j < n_vdata_open;
j++) {
36 if (strcmp(vdata_id_name[
j],
name) == 0) {
37 printf(
"Detaching: %s\n", vdata_id_name[
j]);
38 free(vdata_id_name[
j]);
39 vdata_id_name[
j] = &empty[0];
40 VSdetach(vdata_id_w[
j]);
41 if (aid[
j] != -1) Hendaccess(aid[
j]);
50 for (
j = 0;
j < n_vdata_open;
j++) {
51 if (strcmp(vdata_id_name[
j],
name) == 0) {
60 vdata_id_w[n_vdata_open] = VSattach(fileid_w, -1,
"w");
61 aid[n_vdata_open] = -1;
62 vdata_id_name[n_vdata_open] = (
char *) malloc(strlen(
name) + 1);
64 printf(
"Setting Up: %s %d\n",
name, vdata_id_w[n_vdata_open]);
66 for (
i = 0;
i < n_flds;
i++) {
67 status = VSfdefine(vdata_id_w[n_vdata_open], fldname[
i],
type[
i], 1);
69 printf(
"Error defining \"%s\".\n", fldname[
i]);
75 strcpy(buffer, fldname[0]);
76 for (
i = 1;
i < n_flds;
i++) {
78 strcat(buffer, fldname[
i]);
80 VSsetfields(vdata_id_w[
j], buffer);
82 Vinsert(vgid, vdata_id_w[n_vdata_open]);
83 VSsetname(vdata_id_w[n_vdata_open],
name);
84 VSsetclass(vdata_id_w[n_vdata_open], class1);
86 VSsetblocksize(vdata_id_w[n_vdata_open], 4096 * 6);
91 if (strcmp(class1,
"DataSubordinate") == 0 && noext == 0) {
95 memset(buffer, 0,
sizeof (buffer));
96 status = VSwrite(vdata_id_w[
j], (uint8 *) buffer, 1, FULL_INTERLACE);
97 VSdetach(vdata_id_w[
j]);
98 vdata_id_w[
j] = VSattach(fileid_w, VSfind(fileid_w,
name),
"w");
102 sprintf(&buffer[strlen(buffer)],
".x%02d", prod_count);
106 sfile = fopen(buffer,
"w");
108 if (strrchr(outname,
'/') ==
NULL)
111 strcpy(buffer, strrchr(outname,
'/') + 1);
112 status = fwrite(buffer, 512, 1, sfile);
117 sprintf(&buffer[strlen(buffer)],
".x%02d", prod_count);
118 aid[
j] = HXcreate(fileid_w, DFTAG_VS, (uint16) VSfind(fileid_w,
name),
121 VSdetach(vdata_id_w[
j]);
122 vdata_id_w[
j] = VSattach(fileid_w, VSfind(fileid_w,
name),
"w");
123 VSseek(vdata_id_w[
j], 0);
133 if (n_recs_to_write > 0) {
134 n_write = VSwrite(vdata_id_w[
j],
data, n_recs_to_write, FULL_INTERLACE);
136 if (n_write != n_recs_to_write) {
137 printf(
"n_write: %d n_recs_to_write: %d \n", n_write, n_recs_to_write);
138 printf(
"Error writing to vdata: \"%s\" (%d)\n",
name, vdata_id_w[
j]);
142 printf(
"Writing %d records to %s (%d)\n",
143 n_write,
name, VSelts(vdata_id_w[
j]));