5@brief Demonstrates reading an SDDS file using the SDDS Python module
7This script showcases how to utilize the SDDS Python module to read and display
8the contents of an SDDS (Self Describing Data Set) file. The script performs the
111. Initializes an SDDS object.
122. Loads an existing SDDS file specified by the user.
133. Determines and displays the file mode (binary or ASCII).
144. Prints the description text and contents if available.
155. Lists all parameters, arrays, and columns along with their metadata.
166. Iterates through each loaded page and displays the data for parameters,
20 Ensure that the SDDS Python module is installed and the input SDDS file
21 (`output_all_data_types.sdds`) is present in the working directory.
32 input_file =
"output_all_data_types.sdds"
35 sdds_obj.load(input_file)
38 if sdds_obj.mode == sdds.SDDS_BINARY:
39 print(
"SDDS file mode: SDDS_BINARY")
41 print(
"SDDS file mode: SDDS_ASCII")
44 if sdds_obj.description[0]:
45 print(f
"SDDS file description text: {sdds_obj.description[0]}")
48 if sdds_obj.description[1]:
49 print(f
"SDDS file description contents: {sdds_obj.description[1]}")
52 if sdds_obj.parameterName:
53 print(
"\nParameters:")
54 for i, definition
in enumerate(sdds_obj.parameterDefinition):
55 name = sdds_obj.parameterName[i]
58 description = definition[2]
60 print(f
" Datatype: {datatype}", end=
"")
62 print(f
", Units: {units}", end=
"")
64 print(f
", Description: {description}", end=
"")
68 if sdds_obj.arrayName:
70 for i, definition
in enumerate(sdds_obj.arrayDefinition):
71 name = sdds_obj.arrayName[i]
74 description = definition[2]
75 dimensions = definition[7]
77 print(f
" Datatype: {datatype}, Dimensions: {dimensions}", end=
"")
79 print(f
", Units: {units}", end=
"")
81 print(f
", Description: {description}", end=
"")
85 if sdds_obj.columnName:
87 for i, definition
in enumerate(sdds_obj.columnDefinition):
88 name = sdds_obj.columnName[i]
91 description = definition[2]
93 print(f
" Datatype: {datatype}", end=
"")
95 print(f
", Units: {units}", end=
"")
97 print(f
", Description: {description}", end=
"")
101 for page
in range(sdds_obj.loaded_pages):
102 print(f
"\nPage: {page + 1}")
105 for i, name
in enumerate(sdds_obj.parameterName):
106 value = sdds_obj.parameterData[i][page]
107 print(f
" Parameter '{name}': {value}")
110 for i, name
in enumerate(sdds_obj.arrayName):
111 value = sdds_obj.arrayData[i][page]
112 print(f
" Array '{name}': {value}")
115 for i, name
in enumerate(sdds_obj.columnName):
116 value = sdds_obj.columnData[i][page]
117 print(f
" Column '{name}': {value}")
119if __name__ ==
"__main__":
A class to represent and manipulate SDDS datasets.
sdds_data_type_to_string(data_type_code)
Converts a numeric SDDS data type code to its string representation.
int main(int argc, char **argv)
Main function that processes the SDDS file.