[Mumps2Py:] [44] added a compatibilty function for $DATA.

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 44
Author:   pgallot
Date:     2008-01-23 21:11:26 +0000 (Wed, 23 Jan 2008)

Log Message:
-----------
added a compatibilty function for $DATA.  Note that it does not as yet take Mumps-style Global variables into account.

Modified Paths:
--------------
    trunk/mumps2py/mumpsCL.py


Modified: trunk/mumps2py/mumpsCL.py
===================================================================
--- trunk/mumps2py/mumpsCL.py	2008-01-21 20:35:14 UTC (rev 43)
+++ trunk/mumps2py/mumpsCL.py	2008-01-23 21:11:26 UTC (rev 44)
@@ -14,9 +14,40 @@
 ##
 ##    You should have received a copy of the GNU General Public License
 ##    along with Mumps2Py.  If not, see <http://www.gnu.org/licenses/>.
+"""Compatibility Library to allow Mumps source code translated to Python"""
 
+from types import *
 
 #TODO: first order of business, an iterator to use when translating
 # Mumps for-command. Unlike range, a Mumps iteration includes the terminal
 # value. F i:1:1:10 iterates from 1 to 10, inclusive. the equivalent would be
 # range(1, 11)
+
+def Mf_data(loc_adr_space, name, indices_tuple = None):
+    """Python-equivalent of the Mumps $Data intrinsic
+NOTE: not yet designed to work with Mumps Global variables."""
+
+    if not loc_adr_space.has_key(name):
+        return 0
+    else:
+        the_var = loc_adr_space[name]
+
+        if not isinstance(the_var, DictType):
+            return 1
+        else:
+            if indices_tuple == None:
+                if the_var.has_key( (None) ):
+                    return 11
+                else:
+                    return 10
+            elif the_var.has_key(indices_tuple):
+                the_var = the_var[indices_tuple]
+                if not isinstance(the_var, DictType):
+                    return 1
+                else:
+                    if the_var.has_key( (None) ):
+                        return 11
+                    else:
+                        return 10
+            else:
+                return 0


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/