Ejemplo n.º 1
0
 def get_symbols_list(self):
     slist = []
     if __gdxpy_mode__ == GDX_MODE_API:
         rc, nSymb, nElem = gdxcc.gdxSystemInfo(self.gdxHandle)
         assert rc, 'Unable to retrieve "%s" info' % self.filename
         self.number_symbols = nSymb
         self.number_elements = nElem
         slist = [None]*(nSymb+1)
         for j in range(0,nSymb+1):
             sinfo = self.get_sid_info(j)
             if j==0:
                 sinfo['name'] = 'u'
             slist[j] = gdxsymb(self,sinfo)
     elif __gdxpy_mode__ == GDX_MODE_SHELL:
         cmdline = r'gdxdump.exe {0} Symbols'.format(self.internal_filename)
         symbspeclist = StringIO.StringIO(subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()[0])
         for symbspec in symbspeclist:
             m_obj = re.search(r"^\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(.*)$", symbspec)
             if m_obj != None:
                 sid = m_obj.group(1)
                 sinfo = {
                     'name': m_obj.group(2),
                     'dim': m_obj.group(3),
                     'stype': m_obj.group(4),
                     'desc' : m_obj.group(5).strip() }
                 slist.append(gdxsymb(self,sinfo))
     else:
         raise Exception('Function "get_symbols_list" not available outside GDX API/SHELL mode')
     return slist
Ejemplo n.º 2
0
def file_info(H):
    ret, version, producer = gdxcc.gdxFileVersion(H)
    if ret != 1:
        raise GDX_error("Couldn't get file version")
    ret, symbol_count, element_count = gdxcc.gdxSystemInfo(H)
    if ret != 1:
        raise GDX_error(H, "Couldn't get file info")
    return {"version": version, "producer": producer, "symbol_count": symbol_count, "element_count": element_count}
Ejemplo n.º 3
0
def file_info(H):
    ret, version, producer = gdxcc.gdxFileVersion(H)
    if ret != 1: raise GDX_error("Couldn't get file version")
    ret, symbol_count, element_count = gdxcc.gdxSystemInfo(H)
    if ret != 1: raise GDX_error(H, "Couldn't get file info")
    return {
      "version": version,
      "producer": producer,
      "symbol_count": symbol_count,
      "element_count": element_count
    }
Ejemplo n.º 4
0
    def read(self, filename):
        """
        Opens gdx file at filename and reads meta-data. If not self.lazy_load, 
        also loads all symbols.

        Throws an Error if not self.empty.

        Throws a GdxError if any calls to gdxcc fail.
        """
        if not self.empty:
            raise Error(
                "GdxFile.read can only be used if the GdxFile is .empty")

        # open the file
        rc = gdxcc.gdxOpenRead(self.H, filename)
        if not rc[0]:
            raise GdxError(self.H, "Could not open '{}'".format(filename))
        self._filename = filename

        # read in meta-data ...
        # ... for the file
        ret, self._version, self._producer = gdxcc.gdxFileVersion(self.H)
        if ret != 1:
            raise GdxError(self.H, "Could not get file version")
        ret, symbol_count, element_count = gdxcc.gdxSystemInfo(self.H)
        logger.debug(
            "Opening '{}' with {} symbols and {} elements with lazy_load = {}."
            .format(filename, symbol_count, element_count, self.lazy_load))
        # ... for the symbols
        ret, name, dims, data_type = gdxcc.gdxSymbolInfo(self.H, 0)
        if ret != 1:
            raise GdxError(self.H,
                           "Could not get symbol info for the universal set")
        self.universal_set = GdxSymbol(name,
                                       data_type,
                                       dims=dims,
                                       file=self,
                                       index=0)
        for i in range(symbol_count):
            index = i + 1
            ret, name, dims, data_type = gdxcc.gdxSymbolInfo(self.H, index)
            if ret != 1:
                raise GdxError(
                    self.H,
                    "Could not get symbol info for symbol {}".format(index))
            self.append(
                GdxSymbol(name, data_type, dims=dims, file=self, index=index))

        # read all symbols if not lazy_load
        if not self.lazy_load:
            for symbol in self:
                symbol.load()
        return
Ejemplo n.º 5
0
 def get_symbols_list(self):
     '''Return a list of GdxSymb found in the GdxFile.'''
     slist = []
     rc, nSymb, nElem = gdxcc.gdxSystemInfo(self.gdx_handle)
     assert rc, 'Unable to retrieve "%s" info' % self.filename
     self.number_symbols = nSymb
     self.number_elements = nElem
     slist = [None]*(nSymb+1)
     for j in range(0,nSymb+1):
         sinfo = self.get_sid_info(j)
         if j==0:
             sinfo['name'] = 'universal_set'
         slist[j] = GdxSymb(self,sinfo)
     return slist
Ejemplo n.º 6
0
 def __len__(self):
     ret, sym_count, _uel_cnt = gdxcc.gdxSystemInfo(self._h)
     if ret:
         return sym_count
     else:
         return 0