5@brief Demonstrates writing an SDDS file using the SDDS Python module
7This script illustrates how to utilize the SDDS Python module to create an SDDS (Self Describing Data Set) file.
8The file includes parameters, columns, and arrays covering all supported SDDS data types.
10The script performs the following operations:
111. Initializes an SDDS object.
122. Defines parameters, columns, and arrays for each supported SDDS data type.
133. Populates the defined parameters, columns, and arrays with sample data across multiple pages.
144. Saves the populated data to an SDDS file.
36 output_file =
"output_all_data_types.sdds"
39 sdds_obj.setDescription(
40 "Example output file for demonstration purposes",
41 "Includes parameters, columns, and arrays for every supported datatype."
45 sdds_obj.defineSimpleParameter(
"param_short", SDDS.SDDS_SHORT)
46 sdds_obj.defineSimpleParameter(
"param_ushort", SDDS.SDDS_USHORT)
47 sdds_obj.defineSimpleParameter(
"param_long", SDDS.SDDS_LONG)
48 sdds_obj.defineSimpleParameter(
"param_ulong", SDDS.SDDS_ULONG)
49 sdds_obj.defineSimpleParameter(
"param_long64", SDDS.SDDS_LONG64)
50 sdds_obj.defineSimpleParameter(
"param_ulong64", SDDS.SDDS_ULONG64)
51 sdds_obj.defineSimpleParameter(
"param_float", SDDS.SDDS_FLOAT)
52 sdds_obj.defineSimpleParameter(
"param_double", SDDS.SDDS_DOUBLE)
53 sdds_obj.defineSimpleParameter(
"param_string", SDDS.SDDS_STRING)
54 sdds_obj.defineSimpleParameter(
"param_character", SDDS.SDDS_CHARACTER)
57 sdds_obj.defineSimpleColumn(
"col_short", SDDS.SDDS_SHORT)
58 sdds_obj.defineSimpleColumn(
"col_ushort", SDDS.SDDS_USHORT)
59 sdds_obj.defineSimpleColumn(
"col_long", SDDS.SDDS_LONG)
60 sdds_obj.defineSimpleColumn(
"col_ulong", SDDS.SDDS_ULONG)
61 sdds_obj.defineSimpleColumn(
"col_long64", SDDS.SDDS_LONG64)
62 sdds_obj.defineSimpleColumn(
"col_ulong64", SDDS.SDDS_ULONG64)
63 sdds_obj.defineSimpleColumn(
"col_float", SDDS.SDDS_FLOAT)
64 sdds_obj.defineSimpleColumn(
"col_double", SDDS.SDDS_DOUBLE)
65 sdds_obj.defineSimpleColumn(
"col_string", SDDS.SDDS_STRING)
66 sdds_obj.defineSimpleColumn(
"col_character", SDDS.SDDS_CHARACTER)
70 sdds_obj.defineSimpleArray(
"array_short", SDDS.SDDS_SHORT, 1)
71 sdds_obj.defineSimpleArray(
"array_ushort", SDDS.SDDS_USHORT, 1)
72 sdds_obj.defineSimpleArray(
"array_long", SDDS.SDDS_LONG, 2)
73 sdds_obj.defineSimpleArray(
"array_ulong", SDDS.SDDS_ULONG, 1)
74 sdds_obj.defineSimpleArray(
"array_long64", SDDS.SDDS_LONG64, 1)
75 sdds_obj.defineSimpleArray(
"array_ulong64", SDDS.SDDS_ULONG64, 1)
76 sdds_obj.defineSimpleArray(
"array_float", SDDS.SDDS_FLOAT, 1)
77 sdds_obj.defineSimpleArray(
"array_double", SDDS.SDDS_DOUBLE, 1)
78 sdds_obj.defineSimpleArray(
"array_string", SDDS.SDDS_STRING, 1)
79 sdds_obj.defineSimpleArray(
"array_character", SDDS.SDDS_CHARACTER, 1)
86 sdds_obj.setParameterValue(
"param_short", 1, page=1)
87 sdds_obj.setParameterValue(
"param_ushort", 2, page=1)
88 sdds_obj.setParameterValue(
"param_long", 3, page=1)
89 sdds_obj.setParameterValue(
"param_ulong", 4, page=1)
90 sdds_obj.setParameterValue(
"param_long64", 5, page=1)
91 sdds_obj.setParameterValue(
"param_ulong64", 6, page=1)
92 sdds_obj.setParameterValue(
"param_float", 7.7, page=1)
93 sdds_obj.setParameterValue(
"param_double", 8.8, page=1)
94 sdds_obj.setParameterValue(
"param_string",
"Page 1 String", page=1)
95 sdds_obj.setParameterValue(
"param_character",
"A", page=1)
100 "col_ushort": [3, 4],
103 "col_long64": [9, 10],
104 "col_ulong64": [11, 12],
105 "col_float": [13.1, 14.2],
106 "col_double": [15.3, 16.4],
107 "col_string": [
"String1",
"String2"],
108 "col_character": [
"X",
"Y"],
112 for col_name, col_data
in columns_page1.items():
113 sdds_obj.setColumnValueList(col_name, col_data, page=1)
117 "array_short": [1, 2, 3],
118 "array_ushort": [4, 5, 6],
119 "array_ulong": [10, 11, 12],
120 "array_long64": [13, 14, 15],
121 "array_ulong64": [16, 17, 18],
122 "array_float": [19.1, 20.2, 21.3],
123 "array_double": [22.4, 23.5, 24.6],
124 "array_string": [
"Array1",
"Array2",
"Array3"],
125 "array_character": [
"M",
"N",
"O"],
129 for array_name, array_data
in arrays_page1_1d.items():
130 sdds_obj.setArrayValueList(array_name, array_data, [3], page=1)
134 "array_long": [7, 8, 9, 17, 18, 19],
138 for array_name, array_data
in arrays_page1_2d.items():
139 sdds_obj.setArrayValueList(array_name, array_data, [2, 3], page=1)
146 sdds_obj.setParameterValue(
"param_short", 10, page=2)
147 sdds_obj.setParameterValue(
"param_ushort", 20, page=2)
148 sdds_obj.setParameterValue(
"param_long", 30, page=2)
149 sdds_obj.setParameterValue(
"param_ulong", 40, page=2)
150 sdds_obj.setParameterValue(
"param_long64", 50, page=2)
151 sdds_obj.setParameterValue(
"param_ulong64", 60, page=2)
152 sdds_obj.setParameterValue(
"param_float", 70.7, page=2)
153 sdds_obj.setParameterValue(
"param_double", 80.8, page=2)
154 sdds_obj.setParameterValue(
"param_string",
"Page 2 String", page=2)
155 sdds_obj.setParameterValue(
"param_character",
"B", page=2)
159 "col_short": [21, 22],
160 "col_ushort": [23, 24],
161 "col_long": [25, 26],
162 "col_ulong": [27, 28],
163 "col_long64": [29, 30],
164 "col_ulong64": [31, 32],
165 "col_float": [33.1, 34.2],
166 "col_double": [35.3, 36.4],
167 "col_string": [
"String3",
"String4"],
168 "col_character": [
"Z",
"W"],
172 for col_name, col_data
in columns_page2.items():
173 sdds_obj.setColumnValueList(col_name, col_data, page=2)
177 "array_short": [101, 102, 103],
178 "array_ushort": [104, 105, 106],
179 "array_ulong": [110, 111, 112],
180 "array_long64": [113, 114, 115],
181 "array_ulong64": [116, 117, 118],
182 "array_float": [119.1, 120.2, 121.3],
183 "array_double": [122.4, 123.5, 124.6],
184 "array_string": [
"Array4",
"Array5",
"Array6"],
185 "array_character": [
"P",
"Q",
"R"],
189 for array_name, array_data
in arrays_page2_1d.items():
190 sdds_obj.setArrayValueList(array_name, array_data, [3], page=2)
194 "array_long": [107, 108, 109, 207, 208, 209],
198 for array_name, array_data
in arrays_page2_2d.items():
199 sdds_obj.setArrayValueList(array_name, array_data, [2, 3], page=2)
206 sdds_obj.save(output_file)
208if __name__ ==
"__main__":
int main(int argc, char **argv)
Main function that processes the SDDS file.