Salome HOME
Addition of MEDFileUMesh.__getitem__ in python bindings to ease fetch of MEDCouplingU...
[tools/medcoupling.git] / src / MEDLoader / Swig / CaseReader.py
index 7dc270e575a9f001027b8785af38cf2c2fc5eddb..7fc26718050037185cdd75e7c488e55b02453245 100644 (file)
@@ -1,10 +1,10 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+# Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,7 +17,7 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# Author Anthony GEAY (CEA/DEN/DM2S/STMF/LGLS)
+# Author Anthony GEAY (CEA/DEN/DM2S/STMF/LGLS)
 
 # http://www-vis.lbl.gov/NERSC/Software/ensight/doc/OnlineHelp/UM-C11.pdf
 import numpy as np
@@ -357,36 +357,38 @@ class CaseReader(CaseIO):
             raise Exception("Error with file %s"%(fname))
         geoName=re.match("model:([\W]*)([\w\.]+)",lines[ind+1]).group(2)
         m1,m2,typeOfFile=self.__convertGeo2MED(geoName)
-        fieldsInfo=[]
-        ind=lines.index("VARIABLE\n")
-        end=len(lines)-1
-        if "TIME\n" in lines:
-            end=lines.index("TIME\n")
-            pass
-        for i in xrange(ind+1,end):
-            m=re.match("^([\w]+)[\s]+\per[\s]+([\w]+)[\s]*\:[\s]*([\w]+)[\s]+([\S]+)$",lines[i])
-            if m:
-                if m.groups()[0]=="constant":
-                    continue
-                spatialDisc=m.groups()[1] ; fieldName=m.groups()[2] ; nbOfCompo=self.dictCompo2[m.groups()[0]] ; fieldFileName=m.groups()[3]
-                fieldsInfo.append((fieldName,spatialDisc,nbOfCompo,fieldFileName))
+        fieldsInfo=[] ; nbOfTimeSteps=0
+        if "VARIABLE\n" in lines:
+            ind=lines.index("VARIABLE\n")
+            end=len(lines)-1
+            if "TIME\n" in lines:
+                end=lines.index("TIME\n")
                 pass
+            for i in xrange(ind+1,end):
+                m=re.match("^([\w]+)[\s]+\per[\s]+([\w]+)[\s]*\:[\s]*([\w]+)[\s]+([\S]+)$",lines[i])
+                if m:
+                    if m.groups()[0]=="constant":
+                        continue
+                    spatialDisc=m.groups()[1] ; fieldName=m.groups()[2] ; nbOfCompo=self.dictCompo2[m.groups()[0]] ; fieldFileName=m.groups()[3]
+                    fieldsInfo.append((fieldName,spatialDisc,nbOfCompo,fieldFileName))
+                    pass
+                pass
+            
+            expr=re.compile("number[\s]+of[\s]+steps[\s]*\:[\s]*([\d]+)")
+            tmp=filter(expr.search,lines)
+            if len(tmp)!=0:
+                nbOfTimeSteps=int(expr.search(filter(expr.search,lines)[0]).group(1))
+                expr=re.compile("filename[\s]+start[\s]+number[\s]*\:[\s]*([\d]+)")
+                startIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
+                expr=re.compile("filename[\s]+increment[\s]*\:[\s]*([\d]+)")
+                incrIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
+            else:
+                nbOfTimeSteps=1
+                startIt=0
+                incrIt=1
+                pass
+            curIt=startIt
             pass
-        
-        expr=re.compile("number[\s]+of[\s]+steps[\s]*\:[\s]*([\d]+)")
-        tmp=filter(expr.search,lines)
-        if len(tmp)!=0:
-            nbOfTimeSteps=int(expr.search(filter(expr.search,lines)[0]).group(1))
-            expr=re.compile("filename[\s]+start[\s]+number[\s]*\:[\s]*([\d]+)")
-            startIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
-            expr=re.compile("filename[\s]+increment[\s]*\:[\s]*([\d]+)")
-            incrIt=int(expr.search(filter(expr.search,lines)[0]).group(1))
-        else:
-            nbOfTimeSteps=1
-            startIt=0
-            incrIt=1
-            pass
-        curIt=startIt
         mlfields=MEDFileFields()
         mlfields.resize(len(fieldsInfo)*len(m1))
         i=0