readlog.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#####################################################################################
# This file is part of NS2DDV. #
# #
# Copyright(C) 2011-2018 C. Calgaro (caterina.calgaro@math.univ-lille1.fr) #
# E. Creusé (emmanuel.creuse@math.univ-lille1.fr) #
# T. Goudon (thierry.goudon@inria.fr) #
# A. Mouton (alexandre.mouton@math.univ-lille1.fr) #
# #
# NS2DDV is free software: you can redistribute it and/or modify it under the terms #
# of the GNU General Public License as published by the Free Software Foundation, #
# either version 3 of the License, or (at your option) any later version. #
# #
# NS2DDV is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along with #
# NS2DDV. If not, see <http://www.gnu.org/licenses/>. #
#####################################################################################
from base import *
def read_logfile(namelogfile):
f = open(namelogfile, 'r')
lines = f.readlines()
i = 0
for line in lines:
if (i == 0):
headers = line.split(' - ')
nbdiags = len(headers)
data = []
for j in range(0,len(headers)):
headers[j] = str(headers[j]).strip()
data.append([])
else:
diags = line.split(' ')
while '' in diags:
diags.remove('')
diags = map(float, diags)
for j in range(0,len(diags)):
data[j].append(diags[j])
i = i+1
f.close()
return [headers,data]
def extract_data(headers, data, myheader):
i = 0
if ((myheader[0:2] == 'P(') or (myheader[0:3] == 'UX(') or (myheader[0:3] == 'UY(')):
temp = myheader.split('(')[1]
temp = temp[0:-1]
temp = temp.split(',')
signal = map(float, temp)
for header in headers:
if (header == myheader):
return data[i]
elif ((myheader[0:2] == 'P(') and (header[0:2] == 'P(')):
temp = header.split('(')[1]
temp = temp[0:-1]
temp = temp.split(',')
signaltest = map(float, temp)
if (max([abs(signaltest[0]-signal[0])/abs(signal[0]), abs(signaltest[1]-signal[1])/abs(signal[1])]) < 1e-8):
return data[i]
else:
i = i+1
elif ((myheader[0:3] == 'UX(') and (header[0:3] == 'UX(')):
temp = header.split('(')[1]
temp = temp[0:-1]
temp = temp.split(',')
signaltest = map(float, temp)
if (max([abs(signaltest[0]-signal[0])/abs(signal[0]), abs(signaltest[1]-signal[1])/abs(signal[1])]) < 1e-8):
return data[i]
else:
i = i+1
elif ((myheader[0:3] == 'UY(') and (header[0:3] == 'UY(')):
temp = header.split('(')[1]
temp = temp[0:-1]
temp = temp.split(',')
signaltest = map(float, temp)
if (max([abs(signaltest[0]-signal[0])/abs(signal[0]), abs(signaltest[1]-signal[1])/abs(signal[1])]) < 1e-8):
return data[i]
else:
i = i+1
else:
i = i+1
if (i == len(headers)):
print('Could not find data with header '+myheader)
exit()