36 {
38 int32_t i, j, k, row, str_len;
39 SCANNED_ARG *s_arg;
40 char *input_file, *output_root, output1[1024], output2[1024], tmp_col[256];
41 double xmin, xmax, ymin, ymax, zmin, zmax, x_interval, y_interval, z_interval;
42 int32_t x_dim, y_dim, z_dim, column_names, output_columns, page = 0;
43 char **column_name, **output_column;
44 double ****data;
45
46 input_file = output_root = NULL;
49
50 if (argc < 2) {
51 fprintf(stderr, "%s", USAGE_MESSAGE);
52 exit(EXIT_FAILURE);
53 }
54
55 column_names = output_columns = 0;
56 column_name = output_column = NULL;
57 input_file = s_arg[1].list[0];
58 output_root = (argc == 3) ? s_arg[2].list[0] : input_file;
59
60 snprintf(output1, sizeof(output1), "%s.yz", output_root);
61 snprintf(output2, sizeof(output2), "%s.xz", output_root);
62
63 data = NULL;
66 exit(EXIT_FAILURE);
67 }
68
70 for (i = 0; i < column_names; i++) {
72 output_column =
SDDS_Realloc(output_column, (output_columns + 1) *
sizeof(*output_column));
73 if (!output_column) {
74 fprintf(stderr, "Memory allocation failed for output_column.\n");
75 exit(EXIT_FAILURE);
76 }
77 str_len = strlen(column_name[i]);
78 output_column[output_columns] = malloc(str_len - 1);
79 if (!output_column[output_columns]) {
80 fprintf(stderr, "Memory allocation failed for output_column[%d].\n", output_columns);
81 exit(EXIT_FAILURE);
82 }
83 strncpy(output_column[output_columns], column_name[i], str_len - 2);
84 output_column[output_columns][str_len - 2] = '\0';
85 output_columns++;
86 }
87 }
88
89 data = malloc(sizeof(*data) * output_columns);
90 if (!data) {
91 fprintf(stderr, "Memory allocation failed for data.\n");
92 exit(EXIT_FAILURE);
93 }
94
96 if (page == 0) {
110 exit(EXIT_FAILURE);
111 }
112 setup_output_file(&sdds_out1, output1, 1, output_columns, output_column);
113 setup_output_file(&sdds_out2, output2, 0, output_columns, output_column);
114
115 for (i = 0; i < output_columns; i++) {
116 data[i] = malloc(z_dim * sizeof(**data));
117 if (!data[i]) {
118 fprintf(stderr, "Memory allocation failed for data[%d].\n", i);
119 free_data_memory(data, output_columns, z_dim, y_dim);
120 exit(EXIT_FAILURE);
121 }
122 for (j = 0; j < z_dim; j++) {
123 data[i][j] = malloc(y_dim * sizeof(***data));
124 if (!data[i][j]) {
125 fprintf(stderr, "Memory allocation failed for data[%d][%d].\n", i, j);
126 free_data_memory(data, output_columns, z_dim, y_dim);
127 exit(EXIT_FAILURE);
128 }
129 }
130 }
131 }
132
133 for (i = 0; i < output_columns; i++) {
134 for (j = 1; j <= y_dim; j++) {
135 snprintf(tmp_col, sizeof(tmp_col), "%s_%d", output_column[i], j);
137 if (!data[i][page][j - 1]) {
139 free_data_memory(data, output_columns, z_dim, y_dim);
140 exit(EXIT_FAILURE);
141 }
142 }
143 }
144 page++;
145 }
146
149 free_data_memory(data, output_columns, z_dim, y_dim);
150 exit(EXIT_FAILURE);
151 }
152
153 if (page != z_dim) {
154 free_data_memory(data, output_columns, z_dim, y_dim);
155 fprintf(stderr, "Error: Page count (%d) does not match z-dimension size (%d).\n", page, z_dim);
156 exit(EXIT_FAILURE);
157 }
158
159
160 for (page = 0; page < x_dim; page++) {
163 "origin1", xmin, "origin2", ymin, "origin3", zmin,
164 "max_ext1", xmax, "max_ext2", ymax, "max_ext3", zmax,
165 "delta1", x_interval, "delta2", y_interval, "delta3", z_interval,
166 "numPhysCells1", x_dim, "numPhysCells2", y_dim, "numPhysCells3", z_dim,
167 "Variable1Name", "Y", "Variable2Name", "Z",
168 "ZMinimum", zmin, "ZMaximum", zmax, "ZInterval", z_interval, "ZDimension", z_dim,
169 "YMinimum", ymin, "YMaximum", ymax, "YInterval", y_interval, "YDimension", y_dim,
170 NULL)) {
172 free_data_memory(data, output_columns, z_dim, y_dim);
173 exit(EXIT_FAILURE);
174 }
175
176 for (i = 0; i < output_columns; i++) {
177 row = 0;
178 for (j = 0; j < y_dim; j++) {
179 for (k = 0; k < z_dim; k++) {
181 output_column[i], data[i][k][j][page],
182 "z", k * z_interval + zmin,
183 "y", j * y_interval + ymin, NULL)) {
185 free_data_memory(data, output_columns, z_dim, y_dim);
186 exit(EXIT_FAILURE);
187 }
188 row++;
189 }
190 }
191 }
192
195 free_data_memory(data, output_columns, z_dim, y_dim);
196 exit(EXIT_FAILURE);
197 }
198 }
199
202 free_data_memory(data, output_columns, z_dim, y_dim);
203 exit(EXIT_FAILURE);
204 }
205
206
207 for (page = 0; page < y_dim; page++) {
210 "origin1", xmin, "origin2", ymin, "origin3", zmin,
211 "max_ext1", xmax, "max_ext2", ymax, "max_ext3", zmax,
212 "delta1", x_interval, "delta2", y_interval, "delta3", z_interval,
213 "numPhysCells1", x_dim, "numPhysCells2", y_dim, "numPhysCells3", z_dim,
214 "Variable1Name", "X", "Variable2Name", "Z",
215 "ZMinimum", zmin, "ZMaximum", zmax, "ZInterval", z_interval, "ZDimension", z_dim,
216 "XMinimum", xmin, "XMaximum", xmax, "XInterval", x_interval, "XDimension", x_dim,
217 NULL)) {
219 free_data_memory(data, output_columns, z_dim, y_dim);
220 exit(EXIT_FAILURE);
221 }
222
223 for (i = 0; i < output_columns; i++) {
224 row = 0;
225 for (j = 0; j < x_dim; j++) {
226 for (k = 0; k < z_dim; k++) {
228 output_column[i], data[i][k][page][j],
229 "z", k * z_interval + zmin,
230 "x", j * x_interval + xmin, NULL)) {
232 free_data_memory(data, output_columns, z_dim, y_dim);
233 exit(EXIT_FAILURE);
234 }
235 row++;
236 }
237 }
238 }
239
242 free_data_memory(data, output_columns, z_dim, y_dim);
243 exit(EXIT_FAILURE);
244 }
245 }
246
247 free_data_memory(data, output_columns, z_dim, y_dim);
248
251 exit(EXIT_FAILURE);
252 }
253
254 return EXIT_SUCCESS;
255}
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
int wild_match(char *string, char *template)
Determine whether one string is a wildcard match for another.