#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 17 16:24:09 2016

@author: *******
@Matrikelnummer: 152****
@Seminar: Wissenschaftliches Programmieren in Python 
"""

import numpy as np

mypath= 'imsil_out'

from os import listdir 
onlyfiles= [f for f in listdir(mypath) if f.endswith('.out')] #suche daten mit der Endung .out im ordner mypath
from copy import copy 
yieldliste = copy(onlyfiles)
tiltliste = copy(onlyfiles)
laenge = len(onlyfiles)-1
i=0
while i <=laenge:
    file = mypath+'/'+onlyfiles[i]
    searchfile = open(file, "r")
    for line in searchfile:
        if "tilt=" in line: 
            tiltvalue = line
        if " | Backscattered |" in line:
            yvalue = line
    searchfile.close()
    tiltliste[i]=tiltvalue[18:23]
    yieldliste[i]=yvalue[35:40]
    i=i+1
print('tilt list:',tiltliste)
print('yield field', yieldliste)
#print(auslesen[18:23])
f = open("output", "w+")

f.write("Das ist mein Output File \nTiltliste :")
f.write("\n")
i=0
while i<= laenge:
    f.write(tiltliste[i])
    f.write("\n")
    
    i=i+1
    if i > laenge:
        break
f.write("Yieldliste :\n")
i=0
while i<= laenge:
    f.write(yieldliste[i])
    f.write("\n")
    i=i+1
    if i > laenge:
        break
import matplotlib.pyplot as plt
plt.title('2. Hausübung - Mat.Nr. 1525911')
plt.xlabel('tilt=XXX')
plt.ylabel('Yield (per Ion) ?')
plt.grid(True)
plt.plot(tiltliste,yieldliste)
plt.show()
#print(f)
