SDDSlib
Loading...
Searching...
No Matches
sddsmakedataset.c
Go to the documentation of this file.
1/**
2 * @file sddsmakedataset.c
3 * @brief Creates an SDDS file from input data provided via the command line.
4 *
5 * This program allows users to define parameters, columns, and arrays with associated data
6 * and outputs them into an SDDS (Self Describing Data Set) format file or pipe. It supports
7 * various data types and provides options for customizing the output format.
8 *
9 * @section Usage
10 * ```
11 * sddsmakedataset [<outputFile> | -pipe=out]
12 * [options]
13 * ```
14 *
15 * @section Options
16 * -defaultType=<type>
17 * -parameter=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]
18 * -column=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]
19 * -array=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]
20 * -data=<value>
21 * -noWarnings
22 * -ascii
23 * -description=<string>
24 * -contents=<string>
25 * -append[=merge]
26 * -majorOrder=row|column
27 * -pipe=out
28 *
29 * @copyright
30 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
31 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
32 *
33 * @license
34 * This file is distributed under the terms of the Software License Agreement
35 * found in the file LICENSE included with this distribution.
36 *
37 * @author H. Shang, M. Borland, R. Soliday
38 */
39
40#include "mdb.h"
41#include "SDDS.h"
42#include "scan.h"
43
44/* Enumeration for option types */
45enum option_type {
46 CLO_PARAMETER,
47 CLO_COLUMN,
48 CLO_DATA,
49 CLO_PIPE,
50 CLO_DEFAULTTYPE,
51 CLO_NOWARNINGS,
52 CLO_DESCRIPTION,
53 CLO_CONTENTS,
54 CLO_ASCII,
55 CLO_MAJOR_ORDER,
56 CLO_APPEND,
57 CLO_ARRAY,
58 N_OPTIONS
59};
60
61/* Note: only -pipe=out is valid */
62char *option[N_OPTIONS] = {
63 "parameter",
64 "column",
65 "data",
66 "pipe",
67 "defaultType",
68 "noWarnings",
69 "description",
70 "contents",
71 "ascii",
72 "majorOrder",
73 "append",
74 "array",
75};
76
77char *USAGE =
78 "Usage: sddsmakedataset [<outputFile> | -pipe=out]\n"
79 " [options]\n\n"
80 "Options:\n"
81 " -defaultType=<type>\n"
82 " Specify the default data type for parameters and columns if not specified.\n"
83 " Available types: double, float, long64, ulong64, long, ulong, short, ushort, string, character.\n\n"
84 " -parameter=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]\n"
85 " Define a parameter with optional type, units, symbol, and description.\n"
86 " Must be followed by -data=<value> to provide the parameter's value.\n\n"
87 " -data=<value>\n"
88 " Provide the data value for the preceding -parameter, -column, or -array option.\n\n"
89 " -column=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]\n"
90 " Define a column with optional type, units, symbol, and description.\n"
91 " Must be followed by -data=<listOfCommaSeparatedValues> to provide the column's data.\n\n"
92 " -array=<name>[,type=<string>][,units=<string>][,symbol=<string>][,description=<string>]\n"
93 " Define an array with optional type, units, symbol, and description.\n"
94 " Must be followed by -data=<listOfCommaSeparatedValues> to provide the array's data.\n"
95 " Currently supports only one-dimensional arrays.\n\n"
96 " -noWarnings\n"
97 " Do not print out warning messages.\n\n"
98 " -ascii\n"
99 " Output file in ASCII mode. The default is binary.\n\n"
100 " -description=<string>\n"
101 " Provide a description of the output file.\n\n"
102 " -contents=<string>\n"
103 " Provide contents of the description.\n\n"
104 " -append[=merge]\n"
105 " Append data to an existing file. Use 'merge' to append to the current page.\n\n"
106 " -majorOrder=row|column\n"
107 " Specify output file in row or column major order.\n\n"
108 "<outputFile>\n"
109 " SDDS output file for writing the data.\n\n"
110 "-pipe=out\n"
111 " Output the data in SDDS format to the pipe instead of to a file.\n\n"
112 "Program by Hairong Shang. (" __DATE__ " " __TIME__ ", SVN revision: " SVN_VERSION ")\n";
113
114/* Structures for parameters and columns */
115typedef struct
116{
117 char *name, *dataString;
118 void *data;
119 char *description, *symbol, *unit, *typename;
120 long type;
122
123typedef struct
124{
125 char *name, **dataList;
126 void *data;
127 char *description, *symbol, *unit, *typename;
128 long type, rows;
130
131/* Function prototypes */
132COLUMN_INFO *InitializeColumnInfo();
133PARAMETER_INFO *InitializeParameteterInfo();
134void SetInfoData(PARAMETER_INFO **parameter, long parameters, COLUMN_INFO **column, long columns,
135 COLUMN_INFO **array, long arrays,
136 char *defaultType, long noWarnings, long maxrows);
137void FreeMemory(PARAMETER_INFO **parameter, long parameters, COLUMN_INFO **column, long columns,
138 COLUMN_INFO **array, long arrays, long maxrows);
139
140int main(int argc, char **argv) {
141 SCANNED_ARG *s_arg;
142 SDDS_DATASET outTable;
143 char *defaultType, *outputFile;
144 unsigned long pipeFlags, dummyFlags, majorOrderFlag;
145 PARAMETER_INFO **parameter;
146 COLUMN_INFO **column;
147 COLUMN_INFO **array;
148 long parameters, columns, arrays, previousOption, i, j, i_arg, currentOption, tmpfile_used, noWarnings, maxrows = 0, outputMode;
149 char *input = "obset";
150 char *description, *contents;
151 short columnMajorOrder = 0, append = 0;
152 int64_t rowsPresent;
153 int32_t colIndex, arrayIndex, dsize, startIndex;
154 SDDS_ARRAY *sdds_array = NULL;
155
156 description = contents = NULL;
157 parameter = NULL;
158 column = NULL;
159 array = NULL;
160 parameters = columns = arrays = 0;
161 outputFile = defaultType = NULL;
162 pipeFlags = 0;
163 tmpfile_used = noWarnings = 0;
164 outputMode = SDDS_BINARY;
165
168
169 argc = scanargs(&s_arg, argc, argv);
170 if (argc < 3) {
171 fprintf(stderr, "Error: Insufficient arguments provided.\n\n%s", USAGE);
172 exit(EXIT_FAILURE);
173 }
174 previousOption = -1;
175
176 for (i_arg = 1; i_arg < argc; i_arg++) {
177 if (s_arg[i_arg].arg_type == OPTION) {
178 delete_chars(s_arg[i_arg].list[0], "_");
179 currentOption = match_string(s_arg[i_arg].list[0], option, N_OPTIONS, 0);
180 if (currentOption == CLO_DATA && previousOption != CLO_PARAMETER && previousOption != CLO_COLUMN && previousOption != CLO_ARRAY) {
181 SDDS_Bomb("-data option must follow a -parameter, -column, or -array option.");
182 }
183 switch (currentOption) {
184 case CLO_MAJOR_ORDER:
185 majorOrderFlag = 0;
186 s_arg[i_arg].n_items -= 1;
187 if (s_arg[i_arg].n_items > 0 &&
188 (!scanItemList(&majorOrderFlag, s_arg[i_arg].list + 1, &s_arg[i_arg].n_items, 0,
189 "row", -1, NULL, 0, SDDS_ROW_MAJOR_ORDER,
190 "column", -1, NULL, 0, SDDS_COLUMN_MAJOR_ORDER, NULL)))
191 SDDS_Bomb("Invalid -majorOrder syntax or value.");
192 if (majorOrderFlag & SDDS_COLUMN_MAJOR_ORDER)
193 columnMajorOrder = 1;
194 if (majorOrderFlag & SDDS_ROW_MAJOR_ORDER)
195 columnMajorOrder = 0;
196 break;
197 case CLO_NOWARNINGS:
198 noWarnings = 1;
199 break;
200 case CLO_PARAMETER:
201 if (s_arg[i_arg].n_items < 2)
202 SDDS_Bomb("Invalid -parameter syntax.");
203 parameter = SDDS_Realloc(parameter, sizeof(*parameter) * (parameters + 1));
204 parameter[parameters] = InitializeParameteterInfo();
205 SDDS_CopyString(&(parameter[parameters]->name), s_arg[i_arg].list[1]);
206 s_arg[i_arg].list += 2;
207 s_arg[i_arg].n_items -= 2;
208 if (!(parameter[parameters]->name) || !strlen(parameter[parameters]->name))
209 SDDS_Bomb("Invalid -parameter syntax (no name).");
210 if (s_arg[i_arg].n_items > 0 &&
211 !scanItemList(&dummyFlags, s_arg[i_arg].list, &s_arg[i_arg].n_items, 0,
212 "type", SDDS_STRING, &(parameter[parameters]->typename), 1, 0,
213 "units", SDDS_STRING, &(parameter[parameters]->unit), 1, 0,
214 "symbol", SDDS_STRING, &(parameter[parameters]->symbol), 1, 0,
215 "description", SDDS_STRING, &(parameter[parameters]->description), 1, 0, NULL))
216 SDDS_Bomb("Invalid -parameter syntax.");
217 parameters++;
218 s_arg[i_arg].list -= 2;
219 s_arg[i_arg].n_items += 2;
220 break;
221 case CLO_COLUMN:
222 if (s_arg[i_arg].n_items < 2)
223 SDDS_Bomb("Invalid -column syntax.");
224 column = SDDS_Realloc(column, sizeof(*column) * (columns + 1));
225 column[columns] = InitializeColumnInfo();
226 SDDS_CopyString(&(column[columns]->name), s_arg[i_arg].list[1]);
227 s_arg[i_arg].list += 2;
228 s_arg[i_arg].n_items -= 2;
229 if (!(column[columns]->name) || !strlen(column[columns]->name))
230 SDDS_Bomb("Invalid -column syntax (no name).");
231 if (s_arg[i_arg].n_items > 0 &&
232 (!scanItemList(&dummyFlags, s_arg[i_arg].list, &s_arg[i_arg].n_items, 0,
233 "type", SDDS_STRING, &(column[columns]->typename), 1, 0,
234 "unit", SDDS_STRING, &(column[columns]->unit), 1, 0,
235 "symbol", SDDS_STRING, &(column[columns]->symbol), 1, 0,
236 "description", SDDS_STRING, &(column[columns]->description), 1, 0, NULL)))
237 SDDS_Bomb("Invalid -column syntax.");
238 columns++;
239 s_arg[i_arg].list -= 2;
240 s_arg[i_arg].n_items += 2;
241 break;
242 case CLO_ARRAY:
243 if (s_arg[i_arg].n_items < 2)
244 SDDS_Bomb("Invalid -array syntax.");
245 array = SDDS_Realloc(array, sizeof(*array) * (arrays + 1));
246 array[arrays] = InitializeColumnInfo();
247 SDDS_CopyString(&(array[arrays]->name), s_arg[i_arg].list[1]);
248 s_arg[i_arg].list += 2;
249 s_arg[i_arg].n_items -= 2;
250 if (!(array[arrays]->name) || !strlen(array[arrays]->name))
251 SDDS_Bomb("Invalid -array syntax (no name).");
252 if (s_arg[i_arg].n_items > 0 &&
253 (!scanItemList(&dummyFlags, s_arg[i_arg].list, &s_arg[i_arg].n_items, 0,
254 "type", SDDS_STRING, &(array[arrays]->typename), 1, 0,
255 "unit", SDDS_STRING, &(array[arrays]->unit), 1, 0,
256 "symbol", SDDS_STRING, &(array[arrays]->symbol), 1, 0,
257 "description", SDDS_STRING, &(array[arrays]->description), 1, 0, NULL)))
258 SDDS_Bomb("Invalid -array syntax.");
259 arrays++;
260 s_arg[i_arg].list -= 2;
261 s_arg[i_arg].n_items += 2;
262 break;
263 case CLO_DATA:
264 if (previousOption == CLO_PARAMETER) {
265 parameter[parameters - 1]->dataString = s_arg[i_arg].list[1];
266 }
267 if (previousOption == CLO_COLUMN) {
268 if (((s_arg[i_arg].n_items - 1) == 1) &&
269 (strlen(s_arg[i_arg].list[1]) > 1) &&
270 (((column[columns - 1]->typename) && (strcmp(column[columns - 1]->typename, "character") == 0)) ||
271 ((defaultType) && (strcmp(defaultType, "character") == 0)))) {
272 /* Assume each character is a separate data entry for character type */
273 column[columns - 1]->rows = strlen(s_arg[i_arg].list[1]);
274 column[columns - 1]->dataList = malloc(sizeof(*(column[columns - 1]->dataList)) * column[columns - 1]->rows);
275 for (j = 0; j < column[columns - 1]->rows; j++) {
276 char buffer[2] = {s_arg[i_arg].list[1][j], '\0'};
277 SDDS_CopyString(&column[columns - 1]->dataList[j], buffer);
278 }
279 } else {
280 column[columns - 1]->rows = s_arg[i_arg].n_items - 1;
281 column[columns - 1]->dataList = malloc(sizeof(*(column[columns - 1]->dataList)) * column[columns - 1]->rows);
282 for (j = 0; j < column[columns - 1]->rows; j++)
283 SDDS_CopyString(&column[columns - 1]->dataList[j], s_arg[i_arg].list[j + 1]);
284 }
285 }
286 if (previousOption == CLO_ARRAY) {
287 if (((s_arg[i_arg].n_items - 1) == 1) &&
288 (strlen(s_arg[i_arg].list[1]) > 1) &&
289 (((array[arrays - 1]->typename) && (strcmp(array[arrays - 1]->typename, "character") == 0)) ||
290 ((defaultType) && (strcmp(defaultType, "character") == 0)))) {
291 /* Assume each character is a separate data entry for character type */
292 array[arrays - 1]->rows = strlen(s_arg[i_arg].list[1]);
293 array[arrays - 1]->dataList = malloc(sizeof(*(array[arrays - 1]->dataList)) * array[arrays - 1]->rows);
294 for (j = 0; j < array[arrays - 1]->rows; j++) {
295 char buffer[2] = {s_arg[i_arg].list[1][j], '\0'};
296 SDDS_CopyString(&array[arrays - 1]->dataList[j], buffer);
297 }
298 } else {
299 array[arrays - 1]->rows = s_arg[i_arg].n_items - 1;
300 array[arrays - 1]->dataList = malloc(sizeof(*(array[arrays - 1]->dataList)) * array[arrays - 1]->rows);
301 for (j = 0; j < array[arrays - 1]->rows; j++)
302 SDDS_CopyString(&array[arrays - 1]->dataList[j], s_arg[i_arg].list[j + 1]);
303 }
304 }
305 break;
306 case CLO_DEFAULTTYPE:
307 if (s_arg[i_arg].n_items != 2)
308 SDDS_Bomb("Invalid -defaultType option.");
309 SDDS_CopyString(&defaultType, s_arg[i_arg].list[1]);
310 break;
311 case CLO_PIPE:
312 if (!processPipeOption(s_arg[i_arg].list + 1, s_arg[i_arg].n_items - 1, &pipeFlags))
313 SDDS_Bomb("Invalid -pipe syntax.");
314 if (pipeFlags != USE_STDOUT)
315 SDDS_Bomb("Only -pipe=out syntax is valid.");
316 break;
317 case CLO_DESCRIPTION:
318 if (s_arg[i_arg].n_items != 2)
319 SDDS_Bomb("Invalid -description option.");
320 SDDS_CopyString(&description, s_arg[i_arg].list[1]);
321 break;
322 case CLO_CONTENTS:
323 if (s_arg[i_arg].n_items != 2)
324 SDDS_Bomb("Invalid -contents option.");
325 SDDS_CopyString(&contents, s_arg[i_arg].list[1]);
326 break;
327 case CLO_ASCII:
328 outputMode = SDDS_ASCII;
329 break;
330 case CLO_APPEND:
331 append = 1;
332 if (s_arg[i_arg].n_items != 1) {
333 append = 2;
334 if (s_arg[i_arg].n_items > 2 || strncmp(s_arg[i_arg].list[1], "merge", strlen(s_arg[i_arg].list[1])) != 0)
335 SDDS_Bomb("Invalid -append syntax.");
336 }
337 break;
338 default:
339 fprintf(stderr, "Error: Option %s is invalid.\n", s_arg[i_arg].list[0]);
340 exit(EXIT_FAILURE);
341 break;
342 }
343 previousOption = currentOption;
344 } else {
345 if (outputFile == NULL)
346 SDDS_CopyString(&outputFile, s_arg[i_arg].list[0]);
347 else {
348 fprintf(stderr, "Error: Too many filenames provided (%s).\n", s_arg[i_arg].list[0]);
349 exit(EXIT_FAILURE);
350 }
351 }
352 }
353
354 if (!outputFile && !pipeFlags) {
355 fprintf(stderr, "Error: Either an output file or -pipe=out must be specified.\n\n%s", USAGE);
356 exit(EXIT_FAILURE);
357 }
358 if (outputFile && pipeFlags) {
359 fprintf(stderr, "Error: Only one of output file and -pipe=out can be specified.\n\n%s", USAGE);
360 exit(EXIT_FAILURE);
361 }
362
363 processFilenames("sddsmakedataset", &input, &outputFile, pipeFlags, 1, &tmpfile_used);
364 if (!columns && !parameters && !arrays) {
365 fprintf(stderr, "Error: No data provided for writing.\n\n%s", USAGE);
366 exit(EXIT_FAILURE);
367 }
368 if (contents && !description) {
369 if (!noWarnings) {
370 fprintf(stderr, "Warning: Description text is provided for contents without a description. No description will be written.\n");
371 free(contents);
372 contents = NULL;
373 }
374 }
375 for (i = 0; i < columns; i++)
376 if (maxrows < column[i]->rows)
377 maxrows = column[i]->rows;
378 SetInfoData(parameter, parameters, column, columns, array, arrays, defaultType, noWarnings, maxrows);
379
380 if (append == 0) {
381 /* Write a new file */
382 if (!SDDS_InitializeOutput(&outTable, outputMode, 1, description, contents, outputFile))
383 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
384 outTable.layout.data_mode.column_major = columnMajorOrder;
385 for (i = 0; i < parameters; i++) {
386 if (parameter[i]->dataString) {
387 if (SDDS_DefineParameter(&outTable, parameter[i]->name, parameter[i]->symbol, parameter[i]->unit, parameter[i]->description, NULL, parameter[i]->type, NULL) < 0)
388 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
389 }
390 }
391
392 for (i = 0; i < columns; i++) {
393 if (column[i]->dataList) {
394 if (SDDS_DefineColumn(&outTable, column[i]->name, column[i]->symbol, column[i]->unit, column[i]->description, NULL, column[i]->type, 0) < 0)
395 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
396 }
397 }
398 for (i = 0; i < arrays; i++) {
399 if (array[i]->dataList) {
400 if (SDDS_DefineArray(&outTable, array[i]->name, array[i]->symbol, array[i]->unit, array[i]->description, NULL, array[i]->type, 0, 1, NULL) < 0)
401 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
402 }
403 }
404 if (!SDDS_WriteLayout(&outTable))
405 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
406 }
407 if (append == 1) {
408 /* Append */
409 if (!SDDS_InitializeAppend(&outTable, outputFile))
410 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
411 }
412 if (append == 2) {
413 /* Append to page, merge */
414 if (!SDDS_InitializeAppendToPage(&outTable, outputFile, maxrows, &rowsPresent))
415 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
416 }
417 if (append) {
418 /* Check the parameters, columns, and arrays */
419 for (i = 0; i < parameters; i++) {
420 if (parameter[i]->dataString) {
421 if (SDDS_GetParameterIndex(&outTable, parameter[i]->name) < 0) {
422 fprintf(stderr, "Error: Parameter '%s' does not exist in the existing file.\n", parameter[i]->name);
423 exit(EXIT_FAILURE);
424 }
425 }
426 }
427 if (SDDS_ParameterCount(&outTable) != parameters) {
428 fprintf(stderr, "Error: Parameter count does not match the existing file.\n");
429 exit(EXIT_FAILURE);
430 }
431 for (i = 0; i < columns; i++) {
432 if (column[i]->dataList) {
433 if (SDDS_GetColumnIndex(&outTable, column[i]->name) < 0) {
434 fprintf(stderr, "Error: Column '%s' does not exist in the existing file.\n", column[i]->name);
435 exit(EXIT_FAILURE);
436 }
437 }
438 }
439 if (SDDS_ColumnCount(&outTable) != columns) {
440 fprintf(stderr, "Error: Column count does not match the existing file.\n");
441 exit(EXIT_FAILURE);
442 }
443 for (i = 0; i < arrays; i++) {
444 if (array[i]->dataList) {
445 if (SDDS_GetArrayIndex(&outTable, array[i]->name) < 0) {
446 fprintf(stderr, "Error: Array '%s' does not exist in the existing file.\n", array[i]->name);
447 exit(EXIT_FAILURE);
448 }
449 }
450 }
451 if (SDDS_ArrayCount(&outTable) != arrays) {
452 fprintf(stderr, "Error: Array count does not match the existing file.\n");
453 exit(EXIT_FAILURE);
454 }
455 }
456
457 if (append == 0 || append == 1) {
458 if (!SDDS_StartPage(&outTable, maxrows))
459 SDDS_PrintErrors(stdout, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
460 for (i = 0; i < parameters; i++) {
461 if (parameter[i]->data) {
462 if (!SDDS_SetParameters(&outTable, SDDS_SET_BY_NAME | SDDS_PASS_BY_REFERENCE, parameter[i]->name, parameter[i]->data, NULL))
463 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
464 }
465 }
466 for (i = 0; i < columns; i++) {
467 if (column[i]->data) {
468 if (!SDDS_SetColumn(&outTable, SDDS_SET_BY_NAME, column[i]->data, maxrows, column[i]->name))
469 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
470 }
471 }
472 for (i = 0; i < arrays; i++) {
473 if (array[i]->data) {
474 if (!SDDS_SetArrayVararg(&outTable, array[i]->name, SDDS_CONTIGUOUS_DATA, array[i]->data, array[i]->rows))
475 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
476 }
477 }
478 }
479 if (append == 2) {
480 for (i = 0; i < columns; i++) {
481 if (column[i]->data) {
482 colIndex = SDDS_GetColumnIndex(&outTable, column[i]->name);
483 for (j = 0; j < maxrows; j++) {
484 switch (column[i]->type) {
485 case SDDS_LONGDOUBLE:
486 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
487 colIndex, ((long double *)(column[i]->data))[j], -1) == 0)
488 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
489 break;
490 case SDDS_DOUBLE:
491 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
492 colIndex, ((double *)(column[i]->data))[j], -1) == 0)
493 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
494 break;
495 case SDDS_FLOAT:
496 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
497 colIndex, ((float *)(column[i]->data))[j], -1) == 0)
498 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
499 break;
500 case SDDS_LONG64:
501 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
502 colIndex, ((int64_t *)(column[i]->data))[j], -1) == 0)
503 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
504 break;
505 case SDDS_ULONG64:
506 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
507 colIndex, ((uint64_t *)(column[i]->data))[j], -1) == 0)
508 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
509 break;
510 case SDDS_LONG:
511 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
512 colIndex, ((int32_t *)(column[i]->data))[j], -1) == 0)
513 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
514 break;
515 case SDDS_ULONG:
516 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
517 colIndex, ((uint32_t *)(column[i]->data))[j], -1) == 0)
518 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
519 break;
520 case SDDS_SHORT:
521 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
522 colIndex, ((short *)(column[i]->data))[j], -1) == 0)
523 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
524 break;
525 case SDDS_USHORT:
526 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
527 colIndex, ((unsigned short *)(column[i]->data))[j], -1) == 0)
528 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
529 break;
530 case SDDS_CHARACTER:
531 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
532 colIndex, ((char *)(column[i]->data))[j], -1) == 0)
533 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
534 break;
535 case SDDS_STRING:
536 if (SDDS_SetRowValues(&outTable, SDDS_SET_BY_INDEX | SDDS_PASS_BY_VALUE, rowsPresent + j,
537 colIndex, ((char **)(column[i]->data))[j], -1) == 0)
538 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
539 break;
540 default:
541 SDDS_Bomb("Invalid data type provided.");
542 break;
543 }
544 }
545 }
546 }
547 for (i = 0; i < arrays; i++) {
548 if (array[i]->data) {
549 arrayIndex = SDDS_GetArrayIndex(&outTable, array[i]->name);
550 sdds_array = outTable.array + arrayIndex;
551 dsize = SDDS_type_size[sdds_array->definition->type - 1];
552 startIndex = sdds_array->elements;
553 sdds_array->elements += array[i]->rows;
554 sdds_array->data = SDDS_Realloc(sdds_array->data, dsize * sdds_array->elements);
555 if (array[i]->type == SDDS_STRING) {
556 if (!SDDS_CopyStringArray(((char **)sdds_array->data) + startIndex, array[i]->data, array[i]->rows))
557 SDDS_PrintErrors(stderr, SDDS_EXIT_PrintErrors | SDDS_VERBOSE_PrintErrors);
558 } else {
559 memcpy((char *)sdds_array->data + dsize * startIndex, array[i]->data, dsize * array[i]->rows);
560 }
561 }
562 }
563 }
564
565 if (append == 2) {
566 if (!SDDS_UpdatePage(&outTable, FLUSH_TABLE) || !SDDS_Terminate(&outTable))
567 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
568 } else {
569 if (!SDDS_WritePage(&outTable) || !SDDS_Terminate(&outTable))
570 SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
571 }
572
573 /* Free resources */
574 if (tmpfile_used && !replaceFileAndBackUp(input, outputFile))
575 exit(EXIT_FAILURE);
576 free_scanargs(&s_arg, argc);
577 FreeMemory(parameter, parameters, column, columns, array, arrays, maxrows);
578 if (defaultType)
579 free(defaultType);
580 if (outputFile)
581 free(outputFile);
582 if (description)
583 free(description);
584 if (contents)
585 free(contents);
586 return EXIT_SUCCESS;
587}
588
589COLUMN_INFO *InitializeColumnInfo() {
590 COLUMN_INFO *column = malloc(sizeof(*column));
591 if (!column) {
592 fprintf(stderr, "Error: Memory allocation failed for COLUMN_INFO.\n");
593 exit(EXIT_FAILURE);
594 }
595 column->name = column->unit = column->description = column->symbol = NULL;
596 column->data = NULL;
597 column->typename = NULL;
598 column->rows = 0;
599 column->type = -1;
600 column->dataList = NULL;
601 return column;
602}
603
604PARAMETER_INFO *InitializeParameteterInfo() {
605 PARAMETER_INFO *parameter = malloc(sizeof(*parameter));
606 if (!parameter) {
607 fprintf(stderr, "Error: Memory allocation failed for PARAMETER_INFO.\n");
608 exit(EXIT_FAILURE);
609 }
610 parameter->name = parameter->unit = parameter->description = parameter->symbol = NULL;
611 parameter->typename = NULL;
612 parameter->data = NULL;
613 parameter->type = -1;
614 parameter->dataString = NULL;
615 return parameter;
616}
617
618void SetInfoData(PARAMETER_INFO **parameter, long parameters, COLUMN_INFO **column, long columns, COLUMN_INFO **array, long arrays, char *defaultType,
619 long noWarnings, long maxrows) {
620 long i, j;
621 PARAMETER_INFO *par;
622 COLUMN_INFO *col;
623 char *type = NULL;
624
625 for (i = 0; i < parameters; i++) {
626 par = parameter[i];
627 if (!par->dataString) {
628 if (!noWarnings)
629 fprintf(stderr, "Warning: No data provided for parameter '%s'. It will not be written to the output file.\n", par->name);
630 continue;
631 }
632 if (par->typename)
633 SDDS_CopyString(&type, par->typename);
634 else {
635 if (defaultType)
636 SDDS_CopyString(&type, defaultType);
637 else
638 SDDS_CopyString(&type, "none");
639 }
640 if ((par->type = SDDS_IdentifyType(type)) <= 0) {
641 fprintf(stderr, "Error: Invalid data type '%s' for parameter '%s'.\n", type, par->name);
642 exit(EXIT_FAILURE);
643 }
644 par->data = malloc(sizeof(double)); /* Temporary allocation, actual type handled below */
645 if (!par->data) {
646 fprintf(stderr, "Error: Memory allocation failed for parameter data.\n");
647 exit(EXIT_FAILURE);
648 }
649 switch (par->type) {
650 case SDDS_LONGDOUBLE:
651 *((long double *)par->data) = strtold(par->dataString, NULL);
652 break;
653 case SDDS_DOUBLE:
654 *((double *)par->data) = atof(par->dataString);
655 break;
656 case SDDS_FLOAT:
657 *((float *)par->data) = (float)atof(par->dataString);
658 break;
659 case SDDS_LONG64:
660 *((int64_t *)par->data) = atoll(par->dataString);
661 break;
662 case SDDS_ULONG64:
663 *((uint64_t *)par->data) = strtoull(par->dataString, NULL, 10);
664 break;
665 case SDDS_LONG:
666 *((int32_t *)par->data) = atol(par->dataString);
667 break;
668 case SDDS_ULONG:
669 *((uint32_t *)par->data) = strtoul(par->dataString, NULL, 10);
670 break;
671 case SDDS_SHORT:
672 *((short *)par->data) = (short)atol(par->dataString);
673 break;
674 case SDDS_USHORT:
675 *((unsigned short *)par->data) = (unsigned short)atol(par->dataString);
676 break;
677 case SDDS_STRING:
678 cp_str((char **)par->data, par->dataString);
679 break;
680 case SDDS_CHARACTER:
681 *((char *)par->data) = par->dataString[0];
682 break;
683 default:
684 SDDS_Bomb("Invalid data type encountered while setting parameter data.");
685 break;
686 }
687 free(type);
688 }
689
690 for (i = 0; i < columns; i++) {
691 col = column[i];
692 if (!col->dataList) {
693 if (!noWarnings)
694 fprintf(stderr, "Warning: No data provided for column '%s'. It will not be written to the output file.\n", col->name);
695 continue;
696 }
697 if (col->typename)
698 SDDS_CopyString(&type, col->typename);
699 else {
700 if (defaultType)
701 SDDS_CopyString(&type, defaultType);
702 else
703 SDDS_CopyString(&type, "none");
704 }
705 if ((col->type = SDDS_IdentifyType(type)) <= 0) {
706 fprintf(stderr, "Error: Invalid data type '%s' for column '%s'.\n", type, col->name);
707 exit(EXIT_FAILURE);
708 }
709 if (col->rows < maxrows && !noWarnings)
710 fprintf(stderr, "Warning: Missing data for column '%s'. Filling with zeros.\n", col->name);
711 switch (col->type) {
712 case SDDS_LONGDOUBLE:
713 col->data = malloc(sizeof(long double) * maxrows);
714 if (!col->data) {
715 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
716 exit(EXIT_FAILURE);
717 }
718 for (j = 0; j < col->rows; j++)
719 ((long double *)col->data)[j] = strtold(col->dataList[j], NULL);
720 for (j = col->rows; j < maxrows; j++)
721 ((long double *)col->data)[j] = 0.0L;
722 break;
723 case SDDS_DOUBLE:
724 col->data = malloc(sizeof(double) * maxrows);
725 if (!col->data) {
726 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
727 exit(EXIT_FAILURE);
728 }
729 for (j = 0; j < col->rows; j++)
730 ((double *)col->data)[j] = atof(col->dataList[j]);
731 for (j = col->rows; j < maxrows; j++)
732 ((double *)col->data)[j] = 0.0;
733 break;
734 case SDDS_FLOAT:
735 col->data = malloc(sizeof(float) * maxrows);
736 if (!col->data) {
737 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
738 exit(EXIT_FAILURE);
739 }
740 for (j = 0; j < col->rows; j++)
741 ((float *)col->data)[j] = (float)atof(col->dataList[j]);
742 for (j = col->rows; j < maxrows; j++)
743 ((float *)col->data)[j] = 0.0f;
744 break;
745 case SDDS_LONG64:
746 col->data = malloc(sizeof(int64_t) * maxrows);
747 if (!col->data) {
748 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
749 exit(EXIT_FAILURE);
750 }
751 for (j = 0; j < col->rows; j++)
752 ((int64_t *)col->data)[j] = atoll(col->dataList[j]);
753 for (j = col->rows; j < maxrows; j++)
754 ((int64_t *)col->data)[j] = 0;
755 break;
756 case SDDS_ULONG64:
757 col->data = malloc(sizeof(uint64_t) * maxrows);
758 if (!col->data) {
759 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
760 exit(EXIT_FAILURE);
761 }
762 for (j = 0; j < col->rows; j++)
763 ((uint64_t *)col->data)[j] = strtoull(col->dataList[j], NULL, 10);
764 for (j = col->rows; j < maxrows; j++)
765 ((uint64_t *)col->data)[j] = 0;
766 break;
767 case SDDS_LONG:
768 col->data = malloc(sizeof(int32_t) * maxrows);
769 if (!col->data) {
770 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
771 exit(EXIT_FAILURE);
772 }
773 for (j = 0; j < col->rows; j++)
774 ((int32_t *)col->data)[j] = (int32_t)atol(col->dataList[j]);
775 for (j = col->rows; j < maxrows; j++)
776 ((int32_t *)col->data)[j] = 0;
777 break;
778 case SDDS_ULONG:
779 col->data = malloc(sizeof(uint32_t) * maxrows);
780 if (!col->data) {
781 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
782 exit(EXIT_FAILURE);
783 }
784 for (j = 0; j < col->rows; j++)
785 ((uint32_t *)col->data)[j] = strtoul(col->dataList[j], NULL, 10);
786 for (j = col->rows; j < maxrows; j++)
787 ((uint32_t *)col->data)[j] = 0;
788 break;
789 case SDDS_SHORT:
790 col->data = malloc(sizeof(short) * maxrows);
791 if (!col->data) {
792 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
793 exit(EXIT_FAILURE);
794 }
795 for (j = 0; j < col->rows; j++)
796 ((short *)col->data)[j] = (short)atol(col->dataList[j]);
797 for (j = col->rows; j < maxrows; j++)
798 ((short *)col->data)[j] = 0;
799 break;
800 case SDDS_USHORT:
801 col->data = malloc(sizeof(unsigned short) * maxrows);
802 if (!col->data) {
803 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
804 exit(EXIT_FAILURE);
805 }
806 for (j = 0; j < col->rows; j++)
807 ((unsigned short *)col->data)[j] = (unsigned short)atol(col->dataList[j]);
808 for (j = col->rows; j < maxrows; j++)
809 ((unsigned short *)col->data)[j] = 0;
810 break;
811 case SDDS_CHARACTER:
812 col->data = malloc(sizeof(char) * maxrows);
813 if (!col->data) {
814 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
815 exit(EXIT_FAILURE);
816 }
817 for (j = 0; j < col->rows; j++)
818 ((char *)col->data)[j] = col->dataList[j][0];
819 for (j = col->rows; j < maxrows; j++)
820 ((char *)col->data)[j] = '\0';
821 break;
822 case SDDS_STRING:
823 col->data = malloc(sizeof(char *) * maxrows);
824 if (!col->data) {
825 fprintf(stderr, "Error: Memory allocation failed for column '%s' data.\n", col->name);
826 exit(EXIT_FAILURE);
827 }
828 for (j = 0; j < col->rows; j++)
829 SDDS_CopyString(&((char **)col->data)[j], col->dataList[j]);
830 for (j = col->rows; j < maxrows; j++)
831 SDDS_CopyString(&((char **)col->data)[j], "");
832 break;
833 default:
834 SDDS_Bomb("Invalid data type encountered while setting column data.");
835 break;
836 }
837 free(type);
838 }
839
840 for (i = 0; i < arrays; i++) {
841 col = array[i];
842 if (!col->dataList) {
843 if (!noWarnings)
844 fprintf(stderr, "Warning: No data provided for array '%s'. It will not be written to the output file.\n", col->name);
845 continue;
846 }
847 if (col->typename)
848 SDDS_CopyString(&type, col->typename);
849 else {
850 if (defaultType)
851 SDDS_CopyString(&type, defaultType);
852 else
853 SDDS_CopyString(&type, "none");
854 }
855 if ((col->type = SDDS_IdentifyType(type)) <= 0) {
856 fprintf(stderr, "Error: Invalid data type '%s' for array '%s'.\n", type, col->name);
857 exit(EXIT_FAILURE);
858 }
859 switch (col->type) {
860 case SDDS_LONGDOUBLE:
861 col->data = malloc(sizeof(long double) * col->rows);
862 if (!col->data) {
863 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
864 exit(EXIT_FAILURE);
865 }
866 for (j = 0; j < col->rows; j++)
867 ((long double *)col->data)[j] = strtold(col->dataList[j], NULL);
868 break;
869 case SDDS_DOUBLE:
870 col->data = malloc(sizeof(double) * col->rows);
871 if (!col->data) {
872 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
873 exit(EXIT_FAILURE);
874 }
875 for (j = 0; j < col->rows; j++)
876 ((double *)col->data)[j] = atof(col->dataList[j]);
877 break;
878 case SDDS_FLOAT:
879 col->data = malloc(sizeof(float) * col->rows);
880 if (!col->data) {
881 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
882 exit(EXIT_FAILURE);
883 }
884 for (j = 0; j < col->rows; j++)
885 ((float *)col->data)[j] = (float)atof(col->dataList[j]);
886 break;
887 case SDDS_LONG64:
888 col->data = malloc(sizeof(int64_t) * col->rows);
889 if (!col->data) {
890 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
891 exit(EXIT_FAILURE);
892 }
893 for (j = 0; j < col->rows; j++)
894 ((int64_t *)col->data)[j] = atoll(col->dataList[j]);
895 break;
896 case SDDS_ULONG64:
897 col->data = malloc(sizeof(uint64_t) * col->rows);
898 if (!col->data) {
899 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
900 exit(EXIT_FAILURE);
901 }
902 for (j = 0; j < col->rows; j++)
903 ((uint64_t *)col->data)[j] = strtoull(col->dataList[j], NULL, 10);
904 break;
905 case SDDS_LONG:
906 col->data = malloc(sizeof(int32_t) * col->rows);
907 if (!col->data) {
908 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
909 exit(EXIT_FAILURE);
910 }
911 for (j = 0; j < col->rows; j++)
912 ((int32_t *)col->data)[j] = (int32_t)atol(col->dataList[j]);
913 break;
914 case SDDS_ULONG:
915 col->data = malloc(sizeof(uint32_t) * col->rows);
916 if (!col->data) {
917 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
918 exit(EXIT_FAILURE);
919 }
920 for (j = 0; j < col->rows; j++)
921 ((uint32_t *)col->data)[j] = strtoul(col->dataList[j], NULL, 10);
922 break;
923 case SDDS_SHORT:
924 col->data = malloc(sizeof(short) * col->rows);
925 if (!col->data) {
926 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
927 exit(EXIT_FAILURE);
928 }
929 for (j = 0; j < col->rows; j++)
930 ((short *)col->data)[j] = (short)atol(col->dataList[j]);
931 break;
932 case SDDS_USHORT:
933 col->data = malloc(sizeof(unsigned short) * col->rows);
934 if (!col->data) {
935 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
936 exit(EXIT_FAILURE);
937 }
938 for (j = 0; j < col->rows; j++)
939 ((unsigned short *)col->data)[j] = (unsigned short)atol(col->dataList[j]);
940 break;
941 case SDDS_CHARACTER:
942 col->data = malloc(sizeof(char) * col->rows);
943 if (!col->data) {
944 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
945 exit(EXIT_FAILURE);
946 }
947 for (j = 0; j < col->rows; j++)
948 ((char *)col->data)[j] = col->dataList[j][0];
949 break;
950 case SDDS_STRING:
951 col->data = malloc(sizeof(char *) * col->rows);
952 if (!col->data) {
953 fprintf(stderr, "Error: Memory allocation failed for array '%s' data.\n", col->name);
954 exit(EXIT_FAILURE);
955 }
956 for (j = 0; j < col->rows; j++)
957 SDDS_CopyString(&((char **)col->data)[j], col->dataList[j]);
958 break;
959 default:
960 SDDS_Bomb("Invalid data type encountered while setting array data.");
961 break;
962 }
963 free(type);
964 }
965}
966
967void FreeMemory(PARAMETER_INFO **parameter, long parameters, COLUMN_INFO **column, long columns, COLUMN_INFO **array, long arrays, long maxrows) {
968 long i, j;
969
970 /* Free parameters */
971 for (i = 0; i < parameters; i++) {
972 if (parameter[i]->name)
973 free(parameter[i]->name);
974 if (parameter[i]->data)
975 free(parameter[i]->data);
976 if (parameter[i]->unit)
977 free(parameter[i]->unit);
978 if (parameter[i]->description)
979 free(parameter[i]->description);
980 if (parameter[i]->symbol)
981 free(parameter[i]->symbol);
982 if (parameter[i]->typename)
983 free(parameter[i]->typename);
984 free(parameter[i]);
985 }
986 if (parameters)
987 free(parameter);
988
989 /* Free columns */
990 for (i = 0; i < columns; i++) {
991 if (column[i]->name)
992 free(column[i]->name);
993 if (column[i]->dataList) {
994 for (j = 0; j < column[i]->rows; j++)
995 free(column[i]->dataList[j]);
996 free(column[i]->dataList);
997 }
998 if (column[i]->type != SDDS_STRING) {
999 if (column[i]->data)
1000 free(column[i]->data);
1001 } else {
1002 if (column[i]->data) {
1003 for (j = 0; j < maxrows; j++)
1004 free(((char **)column[i]->data)[j]);
1005 free(column[i]->data);
1006 }
1007 }
1008 if (column[i]->unit)
1009 free(column[i]->unit);
1010 if (column[i]->symbol)
1011 free(column[i]->symbol);
1012 if (column[i]->description)
1013 free(column[i]->description);
1014 free(column[i]);
1015 }
1016 if (columns)
1017 free(column);
1018
1019 /* Free arrays */
1020 for (i = 0; i < arrays; i++) {
1021 if (array[i]->name)
1022 free(array[i]->name);
1023 if (array[i]->dataList) {
1024 for (j = 0; j < array[i]->rows; j++)
1025 free(array[i]->dataList[j]);
1026 free(array[i]->dataList);
1027 }
1028 if (array[i]->type != SDDS_STRING) {
1029 if (array[i]->data)
1030 free(array[i]->data);
1031 } else {
1032 if (array[i]->data) {
1033 for (j = 0; j < array[i]->rows; j++)
1034 free(((char **)array[i]->data)[j]);
1035 free(array[i]->data);
1036 }
1037 }
1038 if (array[i]->unit)
1039 free(array[i]->unit);
1040 if (array[i]->symbol)
1041 free(array[i]->symbol);
1042 if (array[i]->description)
1043 free(array[i]->description);
1044 free(array[i]);
1045 }
1046 if (arrays)
1047 free(array);
1048}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
Definition SDDS_data.c:62
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_SetArrayVararg(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer,...)
Sets the values of an array variable in the SDDS dataset using variable arguments for dimensions.
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_Terminate(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_InitializeAppend(SDDS_DATASET *SDDS_dataset, const char *filename)
Initializes the SDDS dataset for appending data by adding a new page to an existing file.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_InitializeAppendToPage(SDDS_DATASET *SDDS_dataset, const char *filename, int64_t updateInterval, int64_t *rowsPresentReturn)
Initializes the SDDS dataset for appending data to the last page of an existing file.
int32_t SDDS_DefineArray(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
int32_t SDDS_UpdatePage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current page of the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
int32_t SDDS_ParameterCount(SDDS_DATASET *page)
Retrieves the number of parameters in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
int32_t SDDS_ColumnCount(SDDS_DATASET *page)
Retrieves the number of columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
Definition SDDS_utils.c:432
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
Definition SDDS_utils.c:288
int32_t SDDS_IdentifyType(char *typeName)
Identifies the SDDS data type based on its string name.
int32_t SDDS_ArrayCount(SDDS_DATASET *page)
Retrieves the number of arrays in the SDDS dataset.
int32_t SDDS_CheckDatasetStructureSize(int32_t size)
Verifies that the size of the SDDS_DATASET structure matches the expected size.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
Definition SDDS_utils.c:342
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
Definition SDDS_utils.c:856
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
Definition SDDS_utils.c:677
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49
char * cp_str(char **s, char *t)
Copies a string, allocating memory for storage.
Definition cp_str.c:28
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
Definition replacefile.c:75
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
Definition scanargs.c:36
long processPipeOption(char **item, long items, unsigned long *flags)
Definition scanargs.c:356
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
Definition scanargs.c:390
void free_scanargs(SCANNED_ARG **scanned, int argc)
Definition scanargs.c:584
long scanItemList(unsigned long *flags, char **item, long *items, unsigned long mode,...)
Scans a list of items and assigns values based on provided keywords and types.