from numpy import loadtxt
import glob
import os

datapath = ''  ##################put here the location of the data to be loaded, the most recent file will always be loaded#########################

file_list = glob.glob(datapath+'/Archive/*')
lastfile = max(file_list, key=os.path.getctime)

def convtolist(q_pre):
    q = []
    for j in range(len(q_pre)):
        qnew = q_pre[j].split(sep=',')
        for i in range(len(qnew)):
            qnew[i] = qnew[i].replace('[','')
            qnew[i] = qnew[i].replace(']','')
            qnew[i] = float(qnew[i])
        q.append(qnew)
    return q

#grab all variables
t = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = float, skiprows=1, usecols=0, max_rows=None)
q_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#', dtype = list, skiprows=1, usecols=1, max_rows=None)
V_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=2, max_rows=None)
Vambient_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=3, max_rows=None)
Vtotal_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=4, max_rows=None)
E_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=5, max_rows=None)
G_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=6, max_rows=None)
I_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=7, max_rows=None)
s_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=8, max_rows=None)
si_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=10, max_rows=None)
groundcurrent = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = float, skiprows=1, usecols=15, max_rows=None)
temps_pre = loadtxt(lastfile+'\params.txt', comments = None, delimiter = '#-#',dtype = list, skiprows=1, usecols=17, max_rows=None)

q = convtolist(q_pre) #charge
V = convtolist(V_pre) #potential from wire
Vambient = convtolist(Vambient_pre) #ambient potential
Vtotal = convtolist(Vtotal_pre) #V + Vambient
E = convtolist(E_pre) #electric field
sigma = convtolist(G_pre) #conductivity
I = convtolist(I_pre) #current
s = convtolist(s_pre) #cylinder center positions
si = convtolist(si_pre) #cylinder interface positions
temps = convtolist(temps_pre) #temperature