4@file example_load_with_sddsdata.py
5@brief Demonstrates reading an SDDS file using the sddsdata module directly.
7This script showcases how to utilize the sddsdata module to read and display
8the contents of an SDDS (Self Describing Data Set) file. The script performs the
111. Initializes an SDDS dataset for reading.
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 sddsdata module is installed and the input SDDS file
21 (`output_all_data_types.sdds`) is present in the working directory.
28 from sddsdata
import *
32 input_file =
"output_all_data_types.sdds"
35 if InitializeInput(fileIndex, input_file) != 1:
36 raise ValueError(
"Failed to initialize SDDS input file.")
39 mode = GetMode(fileIndex)
40 if mode == sdds.SDDS_BINARY:
41 print(
"SDDS file mode: SDDS_BINARY")
43 print(
"SDDS file mode: SDDS_ASCII")
46 description = GetDescription(fileIndex)
48 print(f
"SDDS file description text: {description[0]}")
50 print(f
"SDDS file description contents: {description[1]}")
53 parameterNames = GetParameterNames(fileIndex)
55 print(
"\nParameters:")
56 for name
in parameterNames:
57 definition = GetParameterDefinition(fileIndex, name)
59 print(f
" Datatype: {sdds.sdds_data_type_to_string(definition[4])}", end=
"")
61 print(f
", Units: {definition[1]}", end=
"")
63 print(f
", Description: {definition[2]}", end=
"")
67 arrayNames = GetArrayNames(fileIndex)
70 for name
in arrayNames:
71 definition = GetArrayDefinition(fileIndex, name)
73 print(f
" Datatype: {sdds.sdds_data_type_to_string(definition[5])}, Dimensions: {definition[7]}", end=
"")
75 print(f
", Units: {definition[1]}", end=
"")
77 print(f
", Description: {definition[2]}", end=
"")
81 columnNames = GetColumnNames(fileIndex)
84 for name
in columnNames:
85 definition = GetColumnDefinition(fileIndex, name)
87 print(f
" Datatype: {sdds.sdds_data_type_to_string(definition[4])}", end=
"")
89 print(f
", Units: {definition[1]}", end=
"")
91 print(f
", Description: {definition[2]}", end=
"")
95 page = ReadPage(fileIndex)
97 print(f
"\nPage: {page}")
100 for name
in parameterNames:
101 value = GetParameter(fileIndex, name)
102 print(f
" Parameter '{name}': {value}")
105 for name
in arrayNames:
106 data = GetArray(fileIndex, name)
107 dimensions = GetArrayDimensions(fileIndex, name)
108 print(f
" Array '{name}': {data}, Dimensions: {dimensions}")
111 for name
in columnNames:
112 data = GetColumn(fileIndex, name)
113 print(f
" Column '{name}': {data}")
115 page = ReadPage(fileIndex)
118 if Terminate(fileIndex) != 1:
119 raise ValueError(
"Failed to terminate SDDS dataset.")
121if __name__ ==
"__main__":