I have to read data from a file. the file is like this.
CIRCUITNAME=CIRCUIT1
00.12 12/20 2.3 23.6
00.12 12/20 2.3 23.6
00.42 12/20 2.2 23.3
00.42 12/20 2.2 23.3
00.42 12/20 2.2 23.3
01.12 12/20 2.2 23.1
01.12 12/20 2.2 23.1
Now, I have coded a function which reads this and return a corresponding numpy array for every column.
def load_ci(filepath):
fileObj=open(filepath, 'r')
time_1=[]
time_2=[]
date_count=[]
t=0
ti=0
d=""
#da=0
loadCurrent_1=[]
surfaceTemp_1=[]
loadCurrent_2=[]
surfaceTemp_2=[]
ambient=[]
read=0
for line in fileObj:
if not line.strip():
continue
if read==1:
if '[AMBIENT]' in line:
read=3
continue
elif 'CIRCUITNAME=CIRCUIT2' in line: read=2
else:
if line!='\n' and '[CIRCUIT2]' not in line:
point=line.split(' ')
date_count.append(point[1])
t=(float(point[0]))
ti=int(t)*3600+(t-int(t))*60*100
time_1.append(ti)
loadCurrent_1.append(float(point[2]))
surfaceTemp_1.append(float(point[3]))
if read==2:
if '[AMBIENT]' in line:
read=3
continue
elif 'CIRCUITNAME=CIRCUIT2' in line: read=2
else:
if line!='\n' and '[CIRCUIT2]' not in line:
point=line.split(' ')
t=(float(point[0]))
ti=int(t)*3600+(t-int(t))*60*100
time_2.append(ti)
loadCurrent_2.append(float(point[2]))
surfaceTemp_2.append(float(point[3]))
if read==3:
if line!='\n':
point=line.split(' ')
ambient.append(float(point[2]))
if 'CIRCUITNAME=CIRCUIT1' in line: read=1
return np.array(loadCurrent_1), np.array(surfaceTemp_1),np.array(loadCurrent_2),np.array(surfaceTemp_2),np.array(ambient),np.array(time_1),np.array(time_2),np.array(date_count)
a= load_ci("2_Horizontal_Drilling_800mm_20121221_001235.ci") print a
But, I could not able to save the month-date as floats because of '/' in between months and dates. I need to save the month-date like '12.05' which means 12th of May. Then when the next day comes '12.05' becomes '12.06' and I have to save the time values accordingly by adding hours for a new day. But I could not able to save my date as a float value. Please give me some suggestions or any other way to resolve this issue.