示例#1
0
文件: sdds.py 项目: lehnertu/TEUFEL
     def load(self, input):
          """Load an SDDS file into an SDDS class."""

          try:
               #open SDDS file
               if sddsdata.InitializeInput(self.index, input) != 1:
                    time.sleep(2)
                    if sddsdata.InitializeInput(self.index, input) != 1:
                         sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

               #get data storage mode (SDDS_ASCII or SDDS_BINARY)
               self.mode = sddsdata.GetMode(self.index)

               #get description text and contents
               self.description = sddsdata.GetDescription(self.index)

               #get parameter names
               self.parameterName = sddsdata.GetParameterNames(self.index)
               numberOfParameters = len(self.parameterName)

               #get column names
               self.columnName = sddsdata.GetColumnNames(self.index)
               numberOfColumns = len(self.columnName)

               #get parameter definitions
               self.parameterDefinition = list(range(numberOfParameters))
               for i in range(numberOfParameters):
                    self.parameterDefinition[i] = sddsdata.GetParameterDefinition(self.index, self.parameterName[i])

               #get column definitions
               self.columnDefinition = list(range(numberOfColumns))
               for i in range(numberOfColumns):
                    self.columnDefinition[i] = sddsdata.GetColumnDefinition(self.index, self.columnName[i])

               #initialize parameter and column data
               self.parameterData = list(range(numberOfParameters))
               self.columnData = list(range(numberOfColumns))
               for i in range(numberOfParameters):
                    self.parameterData[i] = []
               for i in range(numberOfColumns):
                    self.columnData[i] = []

               #read in SDDS data
               page = sddsdata.ReadPage(self.index)
               if page != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
               while page > 0:
                    for i in range(numberOfParameters):
                         self.parameterData[i].append(sddsdata.GetParameter(self.index,i))
                    for i in range(numberOfColumns):
                         self.columnData[i].append(sddsdata.GetColumn(self.index,i))
                    page = sddsdata.ReadPage(self.index)

               #close SDDS file
               if sddsdata.Terminate(self.index) != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

          except:
               sddsdata.PrintErrors(self.SDDS_VERBOSE_PrintErrors)
               raise
示例#2
0
    def Data_Storage_mode(self, input):
        if sddsdata.InitializeInput(self.index, input) != 1:
            time.sleep(2)
            if sddsdata.InitializeInput(self.index, input) != 1:
                sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
        self_data_mode = sddsdata.GetMode(self.index)

        #close SDDS file
        if sddsdata.Terminate(self.index) != 1:
            sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

        return self_data_mode
示例#3
0
文件: sdds.py 项目: rtums/epics-sdds
    def save(self, output):
        """Save an SDDS class to an SDDS file."""

        try:
            #check for invalid SDDS data
            numberOfParameters = len(self.parameterName)
            numberOfColumns = len(self.columnName)
            pages = 0
            if numberOfParameters != len(self.parameterData):
                raise Exception("unmatched parameterName and parameterData")
            if numberOfColumns != len(self.columnData):
                raise Exception("unmatched columnName and columnData")
            if numberOfParameters != len(self.parameterDefinition):
                raise Exception(
                    "unmatched parameterName and parameterDefinition")
            if numberOfColumns != len(self.columnDefinition):
                raise Exception("unmatched columnName and columnDefinition")
            if numberOfParameters > 0:
                pages = len(self.parameterData[0])
            elif numberOfColumns > 0:
                pages = len(self.columnData[0])
            for i in range(numberOfParameters):
                if pages != len(self.parameterData[i]):
                    raise Exception(
                        "unequal number of pages in parameter data")
            for i in range(numberOfColumns):
                if pages != len(self.columnData[i]):
                    raise Exception("unequal number of pages in column data")
            for page in range(pages):
                rows = 0
                if numberOfColumns > 0:
                    rows = len(self.columnData[0][page])
                for i in range(numberOfColumns):
                    if rows != len(self.columnData[i][page]):
                        raise Exception(
                            "unequal number of rows in column data")

            #open SDDS output file
            if sddsdata.InitializeOutput(self.index, self.mode, 1,
                                         self.description[0],
                                         self.description[1], output) != 1:
                sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

            #define parameters and columns
            for i in range(numberOfParameters):
                if sddsdata.DefineParameter(
                        self.index, self.parameterName[i],
                        self.parameterDefinition[i][0],
                        self.parameterDefinition[i][1],
                        self.parameterDefinition[i][2],
                        self.parameterDefinition[i][3],
                        self.parameterDefinition[i][4],
                        self.parameterDefinition[i][5]) == -1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
            for i in range(numberOfColumns):
                if sddsdata.DefineColumn(self.index, self.columnName[i],
                                         self.columnDefinition[i][0],
                                         self.columnDefinition[i][1],
                                         self.columnDefinition[i][2],
                                         self.columnDefinition[i][3],
                                         self.columnDefinition[i][4],
                                         self.columnDefinition[i][5]) == -1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

            #write SDDS header
            if sddsdata.WriteLayout(self.index) != 1:
                sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

            #write SDDS data
            for page in range(pages):
                rows = 0
                if numberOfColumns > 0:
                    rows = len(self.columnData[0][page])
                if sddsdata.StartPage(self.index, rows) != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
                for i in range(numberOfParameters):
                    if sddsdata.SetParameter(self.index, i,
                                             self.parameterData[i][page]) != 1:
                        sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
                for i in range(numberOfColumns):
                    if sddsdata.SetColumn(self.index, i,
                                          self.columnData[i][page]) != 1:
                        sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
                if sddsdata.WritePage(self.index) != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

            #close SDDS output file
            if sddsdata.Terminate(self.index) != 1:
                sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
        except:
            sddsdata.PrintErrors(self.SDDS_VERBOSE_PrintErrors)
            raise
示例#4
0
     def Load_Data(self, input):
          """Load a SDDS file into an SDDS class."""

          try:
               #open SDDS file
               if sddsdata.InitializeInput(self.index, input) != 1:
                    time.sleep(2)
                    if sddsdata.InitializeInput(self.index, input) != 1:
                         sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

               #get data storage mode (SDDS_ASCII or SDDS_BINARY)
               self.mode = sddsdata.GetMode(self.index)
               # if (self.mode == 0):
                    # print ()
                    # print ('Data storage mode is ', 'ASCII')
                    # print ()
               # if (self.mode == 1):
                    # print ()
                    # print ('Data storage mode is ', 'BINARY')
                    # print ()

               #get description text and contents
               self.description = sddsdata.GetDescription(self.index)
               # print ()
               # print ('Description text and contents ')
               # print (self.description)
               # print ()

               #get parameter names
               self.parameterName = sddsdata.GetParameterNames(self.index)
               # print ()
               # print ('Parameter names ')
               # print (self.parameterName)
               # print ()
               numberOfParameters = len(self.parameterName)
               # print ()
               # print ('Number of Parameters = ', numberOfParameters)
               # print ()

               #get column names
               self.columnName = sddsdata.GetColumnNames(self.index)
               # print ()
               # print ('Column names ')
               # print (self.columnName)
               # print ()
               numberOfColumns = len(self.columnName)
               # print ()
               # print ('Number of Columns = ', numberOfColumns)
               # print ()

               #get parameter definitions
               self.parameterDefinition = list(range(numberOfParameters))
               for i in range(numberOfParameters):
                    self.parameterDefinition[i] = sddsdata.GetParameterDefinition(self.index, self.parameterName[i])
               # print ()
               # print ('Parameter definitions ')
               # print (self.parameterDefinition)
               # print ()
                    
               #get column definitions
               self.columnDefinition = list(range(numberOfColumns))
               for i in range(numberOfColumns):
                    self.columnDefinition[i] = sddsdata.GetColumnDefinition(self.index, self.columnName[i])
               # print ()
               # print ('Column definitions ')
               # print (self.columnDefinition)
               # print ()

               #initialize parameter and column data     !!!! this is mentioned by River and Vasiliy !!!!
               self.parameterData = list(range(numberOfParameters))
               self.columnData = list(range(numberOfColumns))
               for i in range(numberOfParameters):
                    self.parameterData[i] = []
               for i in range(numberOfColumns):
                    self.columnData[i] = []

               #read in SDDS data
               page = sddsdata.ReadPage(self.index)
               if page != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
               while page > 0:
                    for i in range(numberOfParameters):
                         self.parameterData[i].append(sddsdata.GetParameter(self.index,i))
                    for i in range(numberOfColumns):
                         self.columnData[i].append(sddsdata.GetColumn(self.index,i))
                    page = sddsdata.ReadPage(self.index)

                    # global x_position
                    # x_position = sddsdata.GetColumn(0,0)
                    # print (x_position[0], x_position[2], x_position[9999])
                    # global y_position
                    # y_position = sddsdata.GetColumn(0,2)
                    # print (y_position[0], y_position[2], y_position[9999])
                    # global z_position
                    # z_position = sddsdata.GetColumn(0,4)
                    # print (z_position[0], z_position[2], z_position[9999])
                    
                    # print (sddsdata.GetColumn(0,0))  # (self.index,i) = (0, 0) means all data for x position
                    # print (sddsdata.GetColumn(0,2))  # (self.index,i) = (0, 2) means all data for y position
                    # print (sddsdata.GetColumn(0,4))  # (self.index,i) = (0, 4) means all data for z position 
                    page = sddsdata.ReadPage(self.index)
                    
               #close SDDS file
               if sddsdata.Terminate(self.index) != 1:
                    sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)

          except:
               sddsdata.PrintErrors(self.SDDS_VERBOSE_PrintErrors)
               raise