Main function to write data to an SDDS file.
< SDDS table structure for data output.
Define parameters for the SDDS table.
Parameters are scalar values associated with each page.
Define arrays for the SDDS table.
Arrays are multidimensional data structures associated with each page.
Define columns for the SDDS table.
Columns are data structures associated with each row of data.
Set parameters for the first page.
Parameters are scalar values that apply to the entire page.
Data for arrays on the first page.
Arrays can have multiple dimensions and are associated with each page.
Data for columns on the first page.
Columns represent data for each row.
Set parameters for the second page.
Data for arrays on the second page.
Data for columns on the second page.
19 {
21
22
24 "SDDS Example", "example.sdds")) {
25 fprintf(stderr, "Error initializing SDDS output.\n");
26 return 1;
27 }
28
29
30
31
32
33
34 if (
46 ) {
48 return 1;
49 }
50
51
52
53
54
55
56 if (
68 ) {
70 return 1;
71 }
72
73
74
75
76
77
78 if (
90 ) {
92 return 1;
93 }
94
95
98 return 1;
99 }
100
101
104 return 1;
105 }
106
107
108
109
110
111
113 "shortParam", (short)10,
114 "ushortParam", (unsigned short)11,
115 "longParam", (int32_t)1000,
116 "ulongParam", (uint32_t)1001,
117 "long64Param", (int64_t)1002,
118 "ulong64Param", (uint64_t)1003,
119 "floatParam", (float)3.14f,
120 "doubleParam", (double)2.71828,
121 "longdoubleParam", (long double)1.1L,
122 "stringParam", "FirstPage",
123 "charParam", 'A',
124 NULL)) {
126 return 1;
127 }
128
129
130
131
132
133
134 int32_t dimension[1] = {3};
135 int32_t dimensionB[2] = {4, 2};
136 short shortArrayData[3] = {1, 2, 3};
137 unsigned short ushortArrayData[3] = {4, 5, 6};
138 int32_t longArrayData[3] = {1000, 2000, 3000};
139 uint32_t ulongArrayData[3] = {1001, 2001, 3001};
140 int64_t long64ArrayData[8] = {1002, 2002, 3002, 4002, 5002, 6002, 7002, 8002};
141 uint64_t ulong64ArrayData[8] = {1003, 2003, 3003, 4003, 5003, 6003, 7003, 8003};
142 float floatArrayData[8] = {1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f};
143 double doubleArrayData[8] = {1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2};
144 long double longdoubleArrayData[8] = {1.3L, 2.3L, 3.3L, 4.3L, 5.3L, 6.3L, 7.3L, 8.3L};
145 char *stringArrayData[8] = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
146 char charArrayData[8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
147
148
149 if (
150 !
SDDS_SetArray(&SDDS_table,
"shortArray", SDDS_CONTIGUOUS_DATA, shortArrayData, dimension) ||
151 !
SDDS_SetArray(&SDDS_table,
"ushortArray", SDDS_CONTIGUOUS_DATA, ushortArrayData, dimension) ||
152 !
SDDS_SetArray(&SDDS_table,
"longArray", SDDS_CONTIGUOUS_DATA, longArrayData, dimension) ||
153 !
SDDS_SetArray(&SDDS_table,
"ulongArray", SDDS_CONTIGUOUS_DATA, ulongArrayData, dimension) ||
154 !
SDDS_SetArray(&SDDS_table,
"long64Array", SDDS_CONTIGUOUS_DATA, long64ArrayData, dimensionB) ||
155 !
SDDS_SetArray(&SDDS_table,
"ulong64Array", SDDS_CONTIGUOUS_DATA, ulong64ArrayData, dimensionB) ||
156 !
SDDS_SetArray(&SDDS_table,
"floatArray", SDDS_CONTIGUOUS_DATA, floatArrayData, dimensionB) ||
157 !
SDDS_SetArray(&SDDS_table,
"doubleArray", SDDS_CONTIGUOUS_DATA, doubleArrayData, dimensionB) ||
158 !
SDDS_SetArray(&SDDS_table,
"longdoubleArray", SDDS_CONTIGUOUS_DATA, longdoubleArrayData, dimensionB) ||
159 !
SDDS_SetArray(&SDDS_table,
"stringArray", SDDS_CONTIGUOUS_DATA, stringArrayData, dimensionB) ||
160 !
SDDS_SetArray(&SDDS_table,
"charArray", SDDS_CONTIGUOUS_DATA, charArrayData, dimensionB)
161 ) {
163 return 1;
164 }
165
166
167
168
169
170
171 int64_t rows = 5;
172 short shortColData[5] = {1, 2, 3, 4, 5};
173 unsigned short ushortColData[5] = {1, 2, 3, 4, 5};
174 int32_t longColData[5] = {100, 200, 300, 400, 500};
175 uint32_t ulongColData[5] = {100, 200, 300, 400, 500};
176 int64_t long64ColData[5] = {100, 200, 300, 400, 500};
177 uint64_t ulong64ColData[5] = {100, 200, 300, 400, 500};
178 float floatColData[5] = {1.1f, 2.2f, 3.3f, 4.4f, 5.5f};
179 double doubleColData[5] = {10.01, 20.02, 30.03, 40.04, 50.05};
180 long double longdoubleColData[5] = {10.01L, 20.02L, 30.03L, 40.04L, 50.05L};
181 char *stringColData[5] = {"one", "two", "three", "four", "five"};
182 char charColData[5] = {'a', 'b', 'c', 'd', 'e'};
183
184
185 if (
186 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, shortColData, rows,
"shortCol") ||
187 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ushortColData, rows,
"ushortCol") ||
188 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, longColData, rows,
"longCol") ||
189 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ulongColData, rows,
"ulongCol") ||
190 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, long64ColData, rows,
"long64Col") ||
191 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ulong64ColData, rows,
"ulong64Col") ||
192 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, floatColData, rows,
"floatCol") ||
193 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, doubleColData, rows,
"doubleCol") ||
194 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, longdoubleColData, rows,
"longdoubleCol") ||
195 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, stringColData, rows,
"stringCol") ||
196 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, charColData, rows,
"charCol")
197 ) {
199 return 1;
200 }
201
202
205 return 1;
206 }
207
208
211 return 1;
212 }
213
214
215
216
218 "shortParam", (short)20,
219 "ushortParam", (unsigned short)21,
220 "longParam", (int32_t)2000,
221 "ulongParam", (uint32_t)2001,
222 "long64Param", (int64_t)2002,
223 "ulong64Param", (uint64_t)2003,
224 "floatParam", (float)6.28f,
225 "doubleParam", (double)1.41421,
226 "longdoubleParam", (long double)2.2L,
227 "stringParam", "SecondPage",
228 "charParam", 'B',
229 NULL)) {
231 return 1;
232 }
233
234
235
236
237 dimension[0] = 2;
238 dimensionB[0] = 2;
239 dimensionB[1] = 2;
240 short shortArrayData2[2] = {7, 8};
241 unsigned short ushortArrayData2[2] = {9, 10};
242 int32_t longArrayData2[2] = {4000, 5000};
243 uint32_t ulongArrayData2[2] = {4001, 5001};
244 int64_t long64ArrayData2[4] = {4002, 5002, 6002, 7002};
245 uint64_t ulong64ArrayData2[4] = {4003, 5003, 6003, 7003};
246 float floatArrayData2[4] = {11.11f, 22.22f, 33.33f, 44.44f};
247 double doubleArrayData2[4] = {33.33, 44.44, 55.55, 66.66};
248 long double longdoubleArrayData2[4] = {55.55L, 66.66L, 77.77L, 88.88L};
249 char *stringArrayData2[4] = {"blue", "red", "yellow", "gold"};
250 char charArrayData2[4] = {'W', 'X', 'Y', 'Z'};
251
252
253 if (
254 !
SDDS_SetArray(&SDDS_table,
"shortArray", SDDS_CONTIGUOUS_DATA, shortArrayData2, dimension) ||
255 !
SDDS_SetArray(&SDDS_table,
"ushortArray", SDDS_CONTIGUOUS_DATA, ushortArrayData2, dimension) ||
256 !
SDDS_SetArray(&SDDS_table,
"longArray", SDDS_CONTIGUOUS_DATA, longArrayData2, dimension) ||
257 !
SDDS_SetArray(&SDDS_table,
"ulongArray", SDDS_CONTIGUOUS_DATA, ulongArrayData2, dimension) ||
258 !
SDDS_SetArray(&SDDS_table,
"long64Array", SDDS_CONTIGUOUS_DATA, long64ArrayData2, dimensionB) ||
259 !
SDDS_SetArray(&SDDS_table,
"ulong64Array", SDDS_CONTIGUOUS_DATA, ulong64ArrayData2, dimensionB) ||
260 !
SDDS_SetArray(&SDDS_table,
"floatArray", SDDS_CONTIGUOUS_DATA, floatArrayData2, dimensionB) ||
261 !
SDDS_SetArray(&SDDS_table,
"doubleArray", SDDS_CONTIGUOUS_DATA, doubleArrayData2, dimensionB) ||
262 !
SDDS_SetArray(&SDDS_table,
"longdoubleArray", SDDS_CONTIGUOUS_DATA, longdoubleArrayData2, dimensionB) ||
263 !
SDDS_SetArray(&SDDS_table,
"stringArray", SDDS_CONTIGUOUS_DATA, stringArrayData2, dimensionB) ||
264 !
SDDS_SetArray(&SDDS_table,
"charArray", SDDS_CONTIGUOUS_DATA, charArrayData2, dimensionB)
265 ) {
267 return 1;
268 }
269
270
271
272
273 rows = 3;
274 short shortColData2[3] = {6, 7, 8};
275 unsigned short ushortColData2[3] = {6, 7, 8};
276 int32_t longColData2[3] = {600, 700, 800};
277 uint32_t ulongColData2[3] = {600, 700, 800};
278 int64_t long64ColData2[3] = {600, 700, 800};
279 uint64_t ulong64ColData2[3] = {600, 700, 800};
280 float floatColData2[3] = {6.6f, 7.7f, 8.8f};
281 double doubleColData2[3] = {60.06, 70.07, 80.08};
282 long double longdoubleColData2[3] = {60.06L, 70.07L, 80.08L};
283 char *stringColData2[3] = {"six", "seven", "eight"};
284 char charColData2[3] = {'f', 'g', 'h'};
285
286
287 if (
288 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, shortColData2, rows,
"shortCol") ||
289 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ushortColData2, rows,
"ushortCol") ||
290 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, longColData2, rows,
"longCol") ||
291 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ulongColData2, rows,
"ulongCol") ||
292 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, long64ColData2, rows,
"long64Col") ||
293 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, ulong64ColData2, rows,
"ulong64Col") ||
294 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, floatColData2, rows,
"floatCol") ||
295 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, doubleColData2, rows,
"doubleCol") ||
296 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, longdoubleColData2, rows,
"longdoubleCol") ||
297 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, stringColData2, rows,
"stringCol") ||
298 !
SDDS_SetColumn(&SDDS_table, SDDS_SET_BY_NAME, charColData2, rows,
"charCol")
299 ) {
301 return 1;
302 }
303
304
307 return 1;
308 }
309
310
312
313 return 0;
314}
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_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_SetArray(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
Sets the values of an array variable in the SDDS dataset using specified dimensions.
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_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_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.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.