# -*- coding: utf-8 -*-## This file is subject to the terms and conditions defined in# file 'LICENSE.txt', which is part of this source code package.#"""Post file reader"""importreimportnumpyasnpfromMuscat.IO.ReaderBaseimportReaderBasefromMuscat.Helpers.LoggerimportDebug,Info
[docs]defRead(self):"""Function that performs the reading of a post file Returns ------- dict read data """self.StartReading()res={}whileTrue:line=self.filePointer.readline()ifline=="":breakl=line.strip("\n")iflen(l)==0:continueif"#volume integrate"inline:continueifl[0]=="#":if"<"inl:s=l.split("<")else:s=re.sub("#"," ",re.sub(" +"," ",l)).split()iflen(s)==1:l="time"+ls=l.split("#")names=[re.sub("[>#]","",x).lstrip().rstrip()forxins]Info("Reading : "+" ".join(names))data=np.empty((0,len(s)),dtype=np.float32)whileTrue:line=self.filePointer.readline()ifline=="":# pragma: no coverbreakl=line.strip("\n")iflen(l)==0:breakl=l.replace("VI","")data=np.vstack((data,np.fromstring(l,sep=" ")))# print(data)foriinrange(len(names)):res[names[i]]=data[:,i]else:self.Print("dont know how t treat "+str(l))# pragma: no coverreturnres
[docs]defCheckIntegrity():string="""# Volume1.000000000000000e+00 2.536237549886229e+05# time <ener>1.000000000000000e+00 -nan# time <enerintegII>1.000000000000000e+00 1.054915810911460e-01#volume integrate# time enerinteg1.000000000000000e+00 VI 4.644104676325955e-02"""theReader=PostReader()theReader.SetStringToRead(string)res=theReader.Read()print(res)return"OK"
if__name__=="__main__":print(CheckIntegrity())# pragma: no cover