# -*- 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.#"""Procast result file reader"""importnumpyasnpimportMuscat.Containers.MeshasUM
[docs]defReadResult(nbNodes,fileName=None,string=None):"""Function API for reading a Procast result file Parameters ---------- nbNodes : int number of nodes to read fileName : str, optional name of the file to be read, by default None string : str, optional data to be read as a string instead of a file, by default None Returns ------- np.ndarray, np.ndarray times steps and temperature read from the procast result file """iffileNameisnotNone:string=open(fileName,'r')elifstringisnotNone:fromioimportStringIOstring=StringIO(string)timeSteps=[]temperature=np.empty((nbNodes,0),dtype=np.double)while(True):line=string.readline()ifline=="":break#for line in string:l=line.strip('\n').lstrip().rstrip()iflen(l)==0:continueifl.find("2 4 1 5 2 1")>-1:line=string.readline()l=line.strip('\n').lstrip().rstrip()s=l.split()timeSteps.append(int(s[3]))newTemp=np.empty((nbNodes,1),dtype=np.double)line=string.readline();line=string.readline();l=line.strip('\n').lstrip().rstrip()while(True):s=l.split()index=int(s[0])-1line=string.readline()l=line.strip('\n').lstrip().rstrip()s=l.split()newTemp[index]=float(s[0])line=string.readline()l=line.strip('\n').lstrip().rstrip()iflen(l)==0:continueifl.find("-1")>-1:breaktemperature=np.hstack((temperature,newTemp))continuereturntimeSteps,temperature