Ejemplo n.º 1
0
    def get_data(
        self,
        wdmpath,
        dsn,
        start=None,
        end=None,
    ):
        """
        Gets attributes and data from a DSN in a WDM file.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        attributes -- a list of the six character code from LIB3.0
        start      -- the start date and time as Python datetime.datetime class
        end        -- the end date and time as Python datetime.datetime class
        """

        wdm_number = self.openfiles[wdmpath]
        if self.verbose: print('getting data from dataset number %d' % dsn)

        if hspf.wdckdtpy(wdm_number, dsn) == 0:
            if self.verbose:
                print('DSN {} in file {} does not exist'.format(dsn, wdmpath))
            return None

        dataset = DSN(wdm_number, dsn, self.message)

        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)
        if retcode == -6:
            print('no data present')
            return None

        if self.verbose: print('reading data from DSN {}'.format(dsn))

        if start != None:
            llsdat = [
                start.year, start.month, start.day, start.hour, start.minute,
                start.second
            ]
        if end != None:
            lledat = [
                end.year, end.month, end.day, end.hour, end.minute, end.second
            ]

        # Determine the number of values in the dataset

        tcode = dataset.get_attribute(17, self.attributes['TCODE '])[0]
        tsstep = dataset.get_attribute(33, self.attributes['TSSTEP'])[0]

        n = hspf.timdifpy(llsdat, lledat, tcode, tsstep)

        # Get the data and put it into dictionary

        data, retcode = hspf.wdtgetpy(wdm_number, dsn, tsstep, llsdat, n, 0,
                                      30, tcode)
        self.retcode_check(retcode, function='wdtget')

        return data
Ejemplo n.º 2
0
    def get_data(self, 
                 wdmpath, 
                 dsn, 
                 start = None, 
                 end = None,
                 ):
        """
        Gets attributes and data from a DSN in a WDM file.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        attributes -- a list of the six character code from LIB3.0
        start      -- the start date and time as Python datetime.datetime class
        end        -- the end date and time as Python datetime.datetime class
        """

        wdm_number = self.openfiles[wdmpath]
        if self.verbose: print('getting data from dataset number %d' % dsn)

        if hspf.wdckdtpy(wdm_number, dsn) == 0:
            if self.verbose: 
                print('DSN {} in file {} does not exist'.format(dsn, wdmpath))
            return None

        dataset = DSN(wdm_number, dsn, self.message)

        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)
        if retcode == -6: 
            print('no data present')
            return None

        if self.verbose: print('reading data from DSN {}'.format(dsn))

        if start != None:
            llsdat = [start.year, start.month, start.day, start.hour, 
                      start.minute, start.second]
        if end != None:
            lledat = [end.year, end.month, end.day, end.hour, end.minute, 
                      end.second]

        # Determine the number of values in the dataset
            
        tcode  = dataset.get_attribute(17, self.attributes['TCODE '])[0]
        tsstep = dataset.get_attribute(33, self.attributes['TSSTEP'])[0]

        n = hspf.timdifpy(llsdat, lledat, tcode, tsstep)

        # Get the data and put it into dictionary

        data, retcode = hspf.wdtgetpy(wdm_number, dsn, tsstep, llsdat, n,
                                      0, 30, tcode)
        self.retcode_check(retcode, function = 'wdtget')

        return data