SDDSlib
Loading...
Searching...
No Matches
SDDS_transfer.c
Go to the documentation of this file.
1/**
2 * @file SDDS_transfer.c
3 * @brief This file provides functions for transferring definitions from one SDDS dataset to another.
4 *
5 * This file provides functions for transferring definitions from one SDDS dataset to another.
6 *
7 * @copyright
8 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
9 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
10 *
11 * @license
12 * This file is distributed under the terms of the Software License Agreement
13 * found in the file LICENSE included with this distribution.
14 *
15 * @author M. Borland, C. Saunders, R. Soliday. H. Shang
16 */
17
18#include "mdb.h"
19#include "match_string.h"
20#include "SDDS.h"
21#include "SDDS_internal.h"
22
23/**
24 * @brief Transfers a column definition from a source dataset to a target dataset.
25 *
26 * This function defines a column in the target SDDS dataset to match the definition of a column in the source SDDS dataset.
27 *
28 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
29 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
30 * @param name The name of the column in the source dataset to be transferred.
31 * @param newName The name of the column in the target dataset. If `NULL`, the original `name` is used.
32 *
33 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
34 */
35int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
36 COLUMN_DEFINITION *coldef;
37
38 if (!name || SDDS_StringIsBlank(name)) {
39 SDDS_SetError("Unable to transfer column definition--NULL or blank name passed (SDDS_TransferColumnDefinition)");
40 return 0;
41 }
42 if (!newName)
43 newName = name;
44 if (!(coldef = SDDS_GetColumnDefinition(source, name))) {
45 SDDS_SetError("Unable to transfer column definition--unknown column named (SDDS_TransferColumnDefinition)");
46 return 0;
47 }
48 if (SDDS_GetColumnIndex(target, newName) >= 0) {
49 SDDS_SetError("Unable to transfer column definition--column already present (SDDS_TransferColumnDefinition)");
50 return 0;
51 }
52 if (SDDS_DefineColumn(target, newName, coldef->symbol, coldef->units, coldef->description, coldef->format_string, coldef->type, coldef->field_length) < 0) {
54 SDDS_SetError("Unable to transfer column definition--call to define column failed (SDDS_TransferColumnDefinition)");
55 return 0;
56 }
58 return 1;
59}
60
61/**
62 * @brief Transfers a parameter definition from a source dataset to a target dataset.
63 *
64 * This function defines a parameter in the target SDDS dataset to match the definition of a parameter in the source SDDS dataset.
65 *
66 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
67 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
68 * @param name The name of the parameter in the source dataset to be transferred.
69 * @param newName The name of the parameter in the target dataset. If `NULL`, the original `name` is used.
70 *
71 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
72 */
73int32_t SDDS_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
75
76 if (!name || SDDS_StringIsBlank(name)) {
77 SDDS_SetError("Unable to transfer parameter definition--NULL or blank name passed (SDDS_TransferParameterDefinition)");
78 return 0;
79 }
80 if (!newName)
81 newName = name;
82 if (!(pardef = SDDS_GetParameterDefinition(source, name))) {
83 SDDS_SetError("Unable to transfer parameter definition--unknown parameter named (SDDS_TransferParameterDefinition)");
84 return 0;
85 }
86 if (SDDS_GetParameterIndex(target, newName) >= 0) {
87 SDDS_SetError("Unable to transfer parameter definition--parameter already present (SDDS_TransferParameterDefinition)");
88 return 0;
89 }
90 if (SDDS_DefineParameter(target, newName, pardef->symbol, pardef->units, pardef->description, pardef->format_string, pardef->type, NULL) < 0) {
92 SDDS_SetError("Unable to transfer parameter definition--call to define parameter failed (SDDS_TransferParameterDefinition)");
93 return 0;
94 }
96 return 1;
97}
98
99/**
100 * @brief Transfers an array definition from a source dataset to a target dataset.
101 *
102 * This function defines an array in the target SDDS dataset to match the definition of an array in the source SDDS dataset.
103 *
104 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
105 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
106 * @param name The name of the array in the source dataset to be transferred.
107 * @param newName The name of the array in the target dataset. If `NULL`, the original `name` is used.
108 *
109 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
110 */
111int32_t SDDS_TransferArrayDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
112 ARRAY_DEFINITION *ardef;
113
114 if (!name || SDDS_StringIsBlank(name)) {
115 SDDS_SetError("Unable to transfer array definition--NULL or blank name passed (SDDS_TransferArrayDefinition)");
116 return 0;
117 }
118 if (!newName)
119 newName = name;
120 if (!(ardef = SDDS_GetArrayDefinition(source, name))) {
121 SDDS_SetError("Unable to transfer array definition--unknown array named (SDDS_TransferArrayDefinition)");
122 return 0;
123 }
124 if (SDDS_GetArrayIndex(target, newName) >= 0) {
125 SDDS_SetError("Unable to transfer array definition--array already present (SDDS_TransferArrayDefinition)");
126 return 0;
127 }
128 if (SDDS_DefineArray(target, newName, ardef->symbol, ardef->units, ardef->description, ardef->format_string, ardef->type, ardef->field_length, ardef->dimensions, ardef->group_name) < 0) {
130 SDDS_SetError("Unable to transfer array definition--call to define array failed (SDDS_TransferArrayDefinition)");
131 return 0;
132 }
134 return 1;
135}
136
137/**
138 * @brief Transfers an associate definition from a source dataset to a target dataset.
139 *
140 * This function defines an associate in the target SDDS dataset to match the definition of an associate in the source SDDS dataset.
141 *
142 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
143 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
144 * @param name The name of the associate in the source dataset to be transferred.
145 * @param newName The name of the associate in the target dataset. If `NULL`, the original `name` is used.
146 *
147 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
148 */
149int32_t SDDS_TransferAssociateDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
151
152 if (!name || SDDS_StringIsBlank(name)) {
153 SDDS_SetError("Unable to transfer associate definition--NULL or blank name passed (SDDS_TransferAssociateDefinition)");
154 return 0;
155 }
156 if (!newName)
157 newName = name;
158 if ((asdef = SDDS_GetAssociateDefinition(target, name))) {
160 SDDS_SetError("Unable to transfer associate definition--associate already present (SDDS_TransferAssociateDefinition)");
161 return 0;
162 }
163 if (!(asdef = SDDS_GetAssociateDefinition(source, newName))) {
164 SDDS_SetError("Unable to transfer associate definition--unknown associate named (SDDS_TransferAssociateDefinition)");
165 return 0;
166 }
167 if (SDDS_DefineAssociate(target, newName, asdef->filename, asdef->path, asdef->description, asdef->contents, asdef->sdds) < 0) {
169 SDDS_SetError("Unable to transfer associate definition--call to define associate failed (SDDS_TransferAssociateDefinition)");
170 return 0;
171 }
173 return 1;
174}
175
176/**
177 * @brief Defines a parameter in the target dataset based on a column definition from the source dataset.
178 *
179 * This function creates a parameter in the target SDDS dataset with properties matching those of a specified column in the source dataset.
180 *
181 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
182 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
183 * @param name The name of the column in the source dataset whose definition is to be used.
184 * @param newName The name of the parameter in the target dataset. If `NULL`, the original `name` is used.
185 *
186 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
187 */
188int32_t SDDS_DefineParameterLikeColumn(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
189 COLUMN_DEFINITION *coldef;
190
191 if (!name || SDDS_StringIsBlank(name)) {
192 SDDS_SetError("Unable to define parameter--NULL or blank name passed (SDDS_DefineParameterLikeColumn)");
193 return 0;
194 }
195 if (!newName)
196 newName = name;
197 if (!(coldef = SDDS_GetColumnDefinition(source, name))) {
198 SDDS_SetError("Unable to define parameter--unknown column named (SDDS_DefineParameterLikeColumn)");
199 return 0;
200 }
201 if (SDDS_GetParameterIndex(target, newName) >= 0) {
202 SDDS_SetError("Unable to define parameter--already exists (SDDS_DefineParameterLikeColumn)");
203 return 0;
204 }
205 if (SDDS_DefineParameter(target, newName, coldef->symbol, coldef->units, coldef->description, coldef->format_string, coldef->type, NULL) < 0) {
207 SDDS_SetError("Unable to define parameter--call to define parameter failed (SDDS_DefineParameterLikeColumn)");
208 return 0;
209 }
211 return 1;
212}
213
214/**
215 * @brief Defines a parameter in the target dataset based on an array definition from the source dataset.
216 *
217 * This function creates a parameter in the target SDDS dataset with properties matching those of a specified array in the source dataset.
218 *
219 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
220 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
221 * @param name The name of the array in the source dataset whose definition is to be used.
222 * @param newName The name of the parameter in the target dataset. If `NULL`, the original `name` is used.
223 *
224 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
225 */
226int32_t SDDS_DefineParameterLikeArray(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
227 ARRAY_DEFINITION *arrayDef;
228
229 if (!name || SDDS_StringIsBlank(name)) {
230 SDDS_SetError("Unable to define parameter--NULL or blank name passed (SDDS_DefineParameterLikeArray)");
231 return 0;
232 }
233 if (!newName)
234 newName = name;
235 if (!(arrayDef = SDDS_GetArrayDefinition(source, name))) {
236 SDDS_SetError("Unable to define parameter--unknown array named (SDDS_DefineParameterLikeArray)");
237 return 0;
238 }
239 if (SDDS_GetParameterIndex(target, newName) >= 0) {
240 SDDS_SetError("Unable to define parameter--already exists (SDDS_DefineParameterLikeArray)");
241 return 0;
242 }
243 if (SDDS_DefineParameter(target, newName, arrayDef->symbol, arrayDef->units, arrayDef->description, arrayDef->format_string, arrayDef->type, NULL) < 0) {
244 SDDS_FreeArrayDefinition(arrayDef);
245 SDDS_SetError("Unable to define parameter--call to define parameter failed (SDDS_DefineParameterLikeArray)");
246 return 0;
247 }
248 SDDS_FreeArrayDefinition(arrayDef);
249 return 1;
250}
251
252/**
253 * @brief Defines a column in the target dataset based on a parameter definition from the source dataset.
254 *
255 * This function creates a column in the target SDDS dataset with properties matching those of a specified parameter in the source dataset.
256 *
257 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
258 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
259 * @param name The name of the parameter in the source dataset whose definition is to be used.
260 * @param newName The name of the column in the target dataset. If `NULL`, the original `name` is used.
261 *
262 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
263 */
264int32_t SDDS_DefineColumnLikeParameter(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
265 PARAMETER_DEFINITION *pardef;
266
267 if (!name || SDDS_StringIsBlank(name)) {
268 SDDS_SetError("Unable to define column--NULL or blank name passed (SDDS_DefineColumnLikeParameter)");
269 return 0;
270 }
271 if (!newName)
272 newName = name;
273 if (!(pardef = SDDS_GetParameterDefinition(source, name))) {
274 SDDS_SetError("Unable to define column--unknown parameter named (SDDS_DefineColumnLikeParameter)");
275 return 0;
276 }
277 if (SDDS_GetColumnIndex(target, newName) >= 0) {
278 SDDS_SetError("Unable to define column--already exists (SDDS_DefineColumnLikeParameter)");
279 return 0;
280 }
281 if (SDDS_DefineColumn(target, newName, pardef->symbol, pardef->units, pardef->description, pardef->format_string, pardef->type, 0) < 0) {
283 SDDS_SetError("Unable to define column--call to define column failed (SDDS_DefineColumnLikeParameter)");
284 return 0;
285 }
287 return 1;
288}
289
290/**
291 * @brief Defines a column in the target dataset based on an array definition from the source dataset.
292 *
293 * This function creates a column in the target SDDS dataset with properties matching those of a specified array in the source dataset.
294 *
295 * @param target Pointer to the `SDDS_DATASET` structure representing the target dataset.
296 * @param source Pointer to the `SDDS_DATASET` structure representing the source dataset.
297 * @param name The name of the array in the source dataset whose definition is to be used.
298 * @param newName The name of the column in the target dataset. If `NULL`, the original `name` is used.
299 *
300 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
301 */
302int32_t SDDS_DefineColumnLikeArray(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName) {
303 ARRAY_DEFINITION *arrayDef;
304
305 if (!name || SDDS_StringIsBlank(name)) {
306 SDDS_SetError("Unable to define column--NULL or blank name passed (SDDS_DefineColumnLikeArray)");
307 return 0;
308 }
309 if (!newName)
310 newName = name;
311 if (!(arrayDef = SDDS_GetArrayDefinition(source, name))) {
312 SDDS_SetError("Unable to define column--unknown array named (SDDS_DefineColumnLikeArray)");
313 return 0;
314 }
315 if (SDDS_GetColumnIndex(target, newName) >= 0) {
316 SDDS_SetError("Unable to define column--already exists (SDDS_DefineColumnLikeArray)");
317 return 0;
318 }
319 if (SDDS_DefineColumn(target, newName, arrayDef->symbol, arrayDef->units, arrayDef->description, arrayDef->format_string, arrayDef->type, 0) < 0) {
320 SDDS_FreeArrayDefinition(arrayDef);
321 SDDS_SetError("Unable to define column--call to define column failed (SDDS_DefineColumnLikeArray)");
322 return 0;
323 }
324 SDDS_FreeArrayDefinition(arrayDef);
325 return 1;
326}
327
328/**
329 * @brief Transfers all parameter definitions from a source dataset to a target dataset.
330 *
331 * This function defines all parameters in the target SDDS dataset to match the parameter definitions in the source SDDS dataset.
332 * It handles existing parameters based on the specified mode.
333 *
334 * @param SDDS_target Pointer to the `SDDS_DATASET` structure representing the target dataset.
335 * @param SDDS_source Pointer to the `SDDS_DATASET` structure representing the source dataset.
336 * @param mode Flags that determine how to handle existing parameters. Valid flags include:
337 * - `0`: Error if a parameter already exists in the target dataset.
338 * - `SDDS_TRANSFER_KEEPOLD`: Retain existing parameters in the target dataset and skip transferring conflicting parameters.
339 * - `SDDS_TRANSFER_OVERWRITE`: Overwrite existing parameters in the target dataset with definitions from the source dataset.
340 *
341 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
342 */
343int32_t SDDS_TransferAllParameterDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode) {
344 SDDS_LAYOUT *target, *source;
345 int32_t i, index;
346 char messBuffer[1024];
347
348 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllParameterDefinitions"))
349 return (0);
350 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllParameterDefinitions"))
351 return (0);
352 if (mode & SDDS_TRANSFER_KEEPOLD && mode & SDDS_TRANSFER_OVERWRITE) {
353 SDDS_SetError("Inconsistent mode flags (SDDS_TransferAllParameterDefinitions)");
354 return 0;
355 }
356 target = &SDDS_target->layout;
357 source = &SDDS_source->layout;
358 SDDS_DeferSavingLayout(SDDS_target, 1);
359 for (i = 0; i < source->n_parameters; i++) {
360 if ((index = SDDS_GetParameterIndex(SDDS_target, source->parameter_definition[i].name)) >= 0) {
361 /* already exists */
362 if (mode & SDDS_TRANSFER_KEEPOLD)
363 continue;
364 if (!(mode & SDDS_TRANSFER_OVERWRITE)) {
365 sprintf(messBuffer, "Unable to define parameter %s---already exists (SDDS_TransferAllParameterDefinitions)", source->parameter_definition[i].name);
366 SDDS_SetError(messBuffer);
367 SDDS_DeferSavingLayout(SDDS_target, 0);
368 return 0;
369 }
370 if (!SDDS_ChangeParameterInformation(SDDS_target, "symbol",
371 &source->parameter_definition[i].symbol,
372 SDDS_BY_INDEX, index) ||
373 !SDDS_ChangeParameterInformation(SDDS_target, "units",
374 &source->parameter_definition[i].units,
375 SDDS_BY_INDEX, index) ||
376 !SDDS_ChangeParameterInformation(SDDS_target, "description",
377 &source->parameter_definition[i].description,
378 SDDS_BY_INDEX, index) ||
379 !SDDS_ChangeParameterInformation(SDDS_target, "format_string",
380 &source->parameter_definition[i].format_string,
381 SDDS_BY_INDEX, index) ||
382 !SDDS_ChangeParameterInformation(SDDS_target, "type",
383 &source->parameter_definition[i].type, SDDS_BY_INDEX, index) ||
384 (source->parameter_definition[i].fixed_value != NULL && !SDDS_ChangeParameterInformation(SDDS_target, "fixed_value", &source->parameter_definition[i].fixed_value, SDDS_BY_INDEX, index))) {
385 SDDS_SetError("Unable to define parameter---problem with overwrite (SDDS_TransferAllParameterDefinitions)");
386 SDDS_DeferSavingLayout(SDDS_target, 0);
387 return 0;
388 }
389 if (source->parameter_definition[i].fixed_value == NULL)
390 target->parameter_definition[index].fixed_value = NULL;
391 target->parameter_definition[index].definition_mode = source->parameter_definition[index].definition_mode;
392 if (target->parameter_definition[index].type == SDDS_STRING)
393 target->parameter_definition[index].memory_number = SDDS_CreateRpnMemory(source->parameter_definition[i].name, 1);
394 else
395 target->parameter_definition[index].memory_number = SDDS_CreateRpnMemory(source->parameter_definition[i].name, 0);
396 } else {
397 if (SDDS_DefineParameter(SDDS_target, source->parameter_definition[i].name,
398 source->parameter_definition[i].symbol, source->parameter_definition[i].units, source->parameter_definition[i].description, source->parameter_definition[i].format_string, source->parameter_definition[i].type, source->parameter_definition[i].fixed_value) < 0) {
399 SDDS_SetError("Unable to define parameter (SDDS_TransferAllParameterDefinitions)");
400 SDDS_DeferSavingLayout(SDDS_target, 0);
401 return 0;
402 }
403 }
404 }
405 SDDS_DeferSavingLayout(SDDS_target, 0);
406 return 1;
407}
408
409/**
410 * @brief Transfers all column definitions from a source dataset to a target dataset.
411 *
412 * This function defines all columns in the target SDDS dataset to match the column definitions in the source SDDS dataset.
413 * It handles existing columns based on the specified mode.
414 *
415 * @param SDDS_target Pointer to the `SDDS_DATASET` structure representing the target dataset.
416 * @param SDDS_source Pointer to the `SDDS_DATASET` structure representing the source dataset.
417 * @param mode Flags that determine how to handle existing columns. Valid flags include:
418 * - `0`: Error if a column already exists in the target dataset.
419 * - `SDDS_TRANSFER_KEEPOLD`: Retain existing columns in the target dataset and skip transferring conflicting columns.
420 * - `SDDS_TRANSFER_OVERWRITE`: Overwrite existing columns in the target dataset with definitions from the source dataset.
421 *
422 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
423 */
424int32_t SDDS_TransferAllColumnDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode) {
425 SDDS_LAYOUT *target, *source;
426 int32_t i, index;
427 char messBuffer[1024];
428
429 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllColumnDefinitions"))
430 return (0);
431 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllColumnDefinitions"))
432 return (0);
433 if (mode & SDDS_TRANSFER_KEEPOLD && mode & SDDS_TRANSFER_OVERWRITE) {
434 SDDS_SetError("Inconsistent mode flags (SDDS_TransferAllColumnDefinitions)");
435 return 0;
436 }
437 target = &SDDS_target->layout;
438 source = &SDDS_source->layout;
439 SDDS_DeferSavingLayout(SDDS_target, 1);
440 for (i = 0; i < source->n_columns; i++)
441 if ((index = SDDS_GetColumnIndex(SDDS_target, source->column_definition[i].name)) >= 0) {
442 /* already exists */
443 if (mode & SDDS_TRANSFER_KEEPOLD)
444 continue;
445 if (!(mode & SDDS_TRANSFER_OVERWRITE)) {
446 sprintf(messBuffer, "Unable to define column %s---already exists (SDDS_TransferAllColumnDefinitions)", source->column_definition[i].name);
447 SDDS_SetError(messBuffer);
448 SDDS_DeferSavingLayout(SDDS_target, 0);
449 return 0;
450 }
451 if (source->column_definition[i].type != target->column_definition[index].type && SDDS_target->n_rows_allocated) {
452 sprintf(messBuffer, "Unable to define column %s---type mismatch and table already allocated (SDDS_TransferAllColumnDefinitions)", source->column_definition[i].name);
453 SDDS_SetError(messBuffer);
454 SDDS_DeferSavingLayout(SDDS_target, 0);
455 return 0;
456 }
457 if (!SDDS_ChangeColumnInformation(SDDS_target, "symbol",
458 &source->column_definition[i].symbol,
459 SDDS_BY_INDEX, index) ||
460 !SDDS_ChangeColumnInformation(SDDS_target, "units",
461 &source->column_definition[i].units,
462 SDDS_BY_INDEX, index) ||
463 !SDDS_ChangeColumnInformation(SDDS_target, "description",
464 &source->column_definition[i].description,
465 SDDS_BY_INDEX, index) ||
466 !SDDS_ChangeColumnInformation(SDDS_target, "format_string",
467 &source->column_definition[i].format_string,
468 SDDS_BY_INDEX, index) ||
469 !SDDS_ChangeColumnInformation(SDDS_target, "type", &source->column_definition[i].type, SDDS_BY_INDEX, index) || !SDDS_ChangeColumnInformation(SDDS_target, "field_length", &source->column_definition[i].field_length, SDDS_BY_INDEX, index)) {
470 SDDS_SetError("Unable to define column---problem with overwrite (SDDS_TransferAllColumnDefinitions)");
471 SDDS_DeferSavingLayout(SDDS_target, 0);
472 return 0;
473 }
474 target->column_definition[index].definition_mode = source->column_definition[index].definition_mode;
475 if (target->column_definition[index].type == SDDS_STRING)
476 target->column_definition[index].memory_number = SDDS_CreateRpnMemory(source->column_definition[i].name, 1);
477 else
478 target->column_definition[index].memory_number = SDDS_CreateRpnMemory(source->column_definition[i].name, 0);
479 } else {
480 if (SDDS_DefineColumn(SDDS_target, source->column_definition[i].name, source->column_definition[i].symbol,
481 source->column_definition[i].units, source->column_definition[i].description, source->column_definition[i].format_string, source->column_definition[i].type, source->column_definition[i].field_length) < 0) {
482 SDDS_SetError("Unable to define column (SDDS_TransferAllColumnDefinitions)");
483 SDDS_DeferSavingLayout(SDDS_target, 0);
484 return 0;
485 }
486 }
487 SDDS_DeferSavingLayout(SDDS_target, 0);
488 return 1;
489}
490
491/**
492 * @brief Transfers all array definitions from a source dataset to a target dataset.
493 *
494 * This function defines all arrays in the target SDDS dataset to match the array definitions in the source SDDS dataset.
495 * Currently, only mode `0` is supported, which results in an error if any array already exists in the target dataset.
496 *
497 * @param SDDS_target Pointer to the `SDDS_DATASET` structure representing the target dataset.
498 * @param SDDS_source Pointer to the `SDDS_DATASET` structure representing the source dataset.
499 * @param mode Flags that determine how to handle existing arrays. Valid value:
500 * - `0`: Error if an array already exists in the target dataset.
501 *
502 * @return `1` on success; `0` on failure. On failure, an error message is recorded.
503 *
504 * @note Non-zero mode flags are not supported for array definitions.
505 */
506int32_t SDDS_TransferAllArrayDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode) {
507 SDDS_LAYOUT *source;
508 int32_t i;
509
510 if (!SDDS_CheckDataset(SDDS_target, "SDDS_TransferAllArrayDefinitions"))
511 return (0);
512 if (!SDDS_CheckDataset(SDDS_source, "SDDS_TransferAllArrayDefinitions"))
513 return (0);
514 if (mode) {
515 /* haven't done this one yet */
516 SDDS_SetError("Nonzero mode not supported for arrays (SDDS_TransferAllArrayDefinitions)");
517 return 0;
518 }
519 source = &SDDS_source->layout;
520 SDDS_DeferSavingLayout(SDDS_target, 1);
521 for (i = 0; i < source->n_arrays; i++)
522 if (SDDS_DefineArray(SDDS_target, source->array_definition[i].name, source->array_definition[i].symbol,
523 source->array_definition[i].units, source->array_definition[i].description,
524 source->array_definition[i].format_string, source->array_definition[i].type, source->array_definition[i].field_length, source->array_definition[i].dimensions, source->array_definition[i].group_name) < 0) {
525 SDDS_SetError("Unable to define array (SDDS_TransferAllArrayDefinitions)");
526 SDDS_DeferSavingLayout(SDDS_target, 0);
527 return 0;
528 }
529 SDDS_DeferSavingLayout(SDDS_target, 0);
530 return 1;
531}
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
void SDDS_DeferSavingLayout(SDDS_DATASET *SDDS_dataset, int32_t mode)
Definition SDDS_copy.c:603
int32_t SDDS_ChangeParameterInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a parameter definition within the SDDS dataset.
Definition SDDS_info.c:485
int32_t SDDS_ChangeColumnInformation(SDDS_DATASET *SDDS_dataset, char *field_name, void *memory, int32_t mode,...)
Modifies a specific field in a column definition within the SDDS dataset.
Definition SDDS_info.c:364
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_DefineAssociate(SDDS_DATASET *SDDS_dataset, const char *name, const char *filename, const char *path, const char *description, const char *contents, int32_t sdds)
Defines an associate for the SDDS dataset.
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_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_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.
int64_t SDDS_CreateRpnMemory(const char *name, short is_string)
Stub function for creating RPN memory when RPN_SUPPORT is not enabled.
Definition SDDS_rpn.c:785
int32_t SDDS_TransferColumnDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a column definition from a source dataset to a target dataset.
int32_t SDDS_TransferAllArrayDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
Transfers all array definitions from a source dataset to a target dataset.
int32_t SDDS_TransferAllParameterDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
Transfers all parameter definitions from a source dataset to a target dataset.
int32_t SDDS_DefineParameterLikeColumn(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a parameter in the target dataset based on a column definition from the source dataset.
int32_t SDDS_TransferArrayDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers an array definition from a source dataset to a target dataset.
int32_t SDDS_TransferAssociateDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers an associate definition from a source dataset to a target dataset.
int32_t SDDS_DefineColumnLikeArray(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a column in the target dataset based on an array definition from the source dataset.
int32_t SDDS_DefineParameterLikeArray(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a parameter in the target dataset based on an array definition from the source dataset.
int32_t SDDS_DefineColumnLikeParameter(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Defines a column in the target dataset based on a parameter definition from the source dataset.
int32_t SDDS_TransferParameterDefinition(SDDS_DATASET *target, SDDS_DATASET *source, char *name, char *newName)
Transfers a parameter definition from a source dataset to a target dataset.
int32_t SDDS_TransferAllColumnDefinitions(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, uint32_t mode)
Transfers all column definitions from a source dataset to a target dataset.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
ASSOCIATE_DEFINITION * SDDS_GetAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified associate from the SDDS dataset.
Definition SDDS_utils.c:883
ARRAY_DEFINITION * SDDS_GetArrayDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified array from the SDDS dataset.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
PARAMETER_DEFINITION * SDDS_GetParameterDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified parameter from the SDDS dataset.
int32_t SDDS_FreeParameterDefinition(PARAMETER_DEFINITION *source)
Frees memory allocated for a parameter definition.
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_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
Definition SDDS_utils.c:552
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_FreeAssociateDefinition(ASSOCIATE_DEFINITION *source)
Frees memory allocated for an associate definition.
Definition SDDS_utils.c:944
int32_t SDDS_FreeColumnDefinition(COLUMN_DEFINITION *source)
Frees memory allocated for a column definition.
COLUMN_DEFINITION * SDDS_GetColumnDefinition(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the definition of a specified column from the SDDS dataset.
Definition SDDS_utils.c:978
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85