def get_LinkSeries(self,
                       LinkInd,
                       LinkAttr,
                       SeriesStartInd=0,
                       SeriesLen=-1):
        """
        Purpose: Get time series results for particular attribute. Specify series
        start and length using seriesStart and seriesLength respectively.

        SeriesLen = -1 Default input: Gets data from Series Start Ind to end
        
        """
        if SeriesLen > self.numPeriods:
            raise Exception("Outside Number of TimeSteps")
        elif SeriesLen == -1:
            SeriesLen = self.numPeriods

        sLength = c_int()
        ErrNo1 = c_int()
        SeriesPtr = _lib.ENR_newOutValueSeries(self.enrapi, SeriesStartInd,
                                               SeriesLen, byref(sLength),
                                               byref(ErrNo1))
        ErrNo2 = _lib.ENR_getLinkSeries(self.enrapi, LinkInd, LinkAttr,
                                        SeriesStartInd, sLength.value,
                                        SeriesPtr)
        BldArray = [SeriesPtr[i] for i in range(sLength.value)]
        ret = _lib.ENR_free(SeriesPtr)

        return BldArray
Beispiel #2
0
    def get_series(self, output, attribute, start_index=0, end_index=-1):
        """
            Purpose: Get time series results for the requested attribute.
            Args
            output: OutputObject that already has the desired output file open.
            attribute: attribute to get values of - must be an ENR_attribute from self.Attributes.
            start_index: first time index to retrieve, default = 0 for first time index.
            end_index: last time index to retrieve, or -1 to get all values starting at start_index.
        """
        if end_index == -1:
            end_index = output.num_periods - 1
        if start_index < 0:
            raise Exception("get_series start_index " + str(start_index) +
                            " cannot be less than zero.")
        if start_index >= output.num_periods:
            raise Exception("get_series start_index " + str(start_index) +
                            " must be less than number of time steps " +
                            str(output.num_periods))
        if end_index < start_index:
            raise Exception("get_series end_index " + str(end_index) +
                            " less than start_index " + str(start_index))
        if end_index >= output.num_periods:
            raise Exception("get_series end_index " + str(end_index) +
                            " must be less than number of time steps " +
                            str(output.num_periods))
        returned_length = c_int()
        error_new = c_int()
        ask_for_end = end_index
        # if output.newOutValueSeriesLengthIsEnd:
        #     ask_for_end += start_index + 1
        series_pointer = _lib.ENR_newOutValueSeries(output.ptrapi, start_index,
                                                    ask_for_end,
                                                    byref(returned_length),
                                                    byref(error_new))
        if error_new.value != 0:
            print("Error " + str(error_new.value) +
                  " allocating series start=" + str(start_index) + ", end=" +
                  str(ask_for_end))
            output._raise_error(error_new.value)

        if self.index >= 0:
            error_get = self._get_series(output.ptrapi, self.index,
                                         attribute.index, start_index,
                                         returned_length.value, series_pointer)
        else:
            error_get = self._get_series(output.ptrapi, attribute.index,
                                         start_index, returned_length.value,
                                         series_pointer)

        if error_get != 0:
            print("Error reading series " + self.TypeLabel + " " +
                  str(self.name) + ', att #' + str(attribute.index))
            output._raise_error(error_get)

        build_array = [series_pointer[i] for i in range(returned_length.value)]
        _lib.ENR_free(series_pointer)
        return build_array
Beispiel #3
0
    def _measure_new_out_value_series(self):
        """Test ENR_newOutValueSeries to see whether it treats the requested length as length or end.
            Sets self.newOutValueSeriesLengthIsEnd flag so we can adjust how we call this method."""

        returned_length = c_int()
        error_new = c_int()

        try:
            series_pointer = _lib.ENR_newOutValueSeries(
                self.ptrapi, 0, 1, byref(returned_length), byref(error_new))
            if error_new.value != 0:
                print(
                    "Error allocating series start to test ENR_newOutValueSeries: "
                    + str(error_new.value))
                self._raise_error(error_new.value)
            self.newOutValueSeriesLengthIsEnd = (returned_length.value == 1)
            _lib.ENR_free(series_pointer)
        except Exception as ex:
            print(str(ex))
            raise Exception(
                "SWMM output error calling ENR_newOutValueSeries: " + str(ex))