import os import sys import re import matplotlib.dates as mdates import time import datetime,pytz import calendar from datetime import datetime import numpy # matrix initialise global date global xutc1 global xutc2 global secos1 global secos2 global inc1 global inc2 global inc12 global inc22 global ertimesec1 global ertimesec2 date = [] secos1 = [] secos2 = [] inc1 = [] inc2 = [] inc12 = [] inc22 = [] xutc1=[] xutc2=[] ertimesec1 =[] ertimesec2 =[] def replcomma(file_name): x = open(file_name) if ("," in x.read()): x.seek(0) s=x.read().replace(",", "." ) x.close() x=open(file_name,"w") x.write(s) x.close return now = time.time() if len(sys.argv) < 3: print('*********************************************************') print('Correct usage "python cernpli-digest-data.py input_file output_file\n (example python cernpli-digest-data.py 2019.08.08-RAW.txt digest-2019.08.08.dat)"') print('*********************************************************') exit(1) filepli = sys.argv[1] fileout = sys.argv[2] b = filepli.split("-") c = b[0].split(".") # extracting the date from the name of the file dateq = c[0] + "-" + c[1] + "-" + c[2] d = filepli.split("-") HomeDir = os.getenv('HOME') print(filepli) print("accessed file ", filepli) #filerr1 = c[0] + "." + c[1] + "-HIST.txt" # with open(filerr1,"r") as errf1: # err1 = errf1.readlines() # errf1.close() # for j1, linee1 in enumerate(err1): # if (d[0] in linee1 and "Error" in linee1): # print(linee1) # columne1 = linee1.split() # ertimes1 = dateq + " " + columne1[3] # ertime1 = datetime.strptime(ertimes1,'%Y-%m-%d %H:%M:%S') # ertimesec1.append(float(calendar.timegm(time.strptime(str(ertime1), '%Y-%m-%d %H:%M:%S')))) replcomma(filepli) ffff = open(fileout,'w') with open(filepli,"r") as quake1: data1 = quake1.readlines()[:-1] quake1.close() for i1, linea1 in enumerate(data1): column1 = linea1.split('\t') tempo1 = column1[0] corrfull1 = dateq + " " + tempo1 seco = float(calendar.timegm(time.strptime(corrfull1, '%Y-%m-%d %H:%M:%S.%f'))) #- time.timezone millis =float(tempo1[len(tempo1)-3:])/1000. secop = seco + millis #- time.timezone secos1.append(secop) xutc1.append(secop) wl1 = float(column1[1]) wl2 = float(column1[2]) wl3 = float(column1[3]) wl4 = float(column1[4]) rp1 = float(column1[5]) rp2 = float(column1[6]) rp3 = float(column1[7]) rp4 = float(column1[8]) if (column1[7] != 'NaN'): inc2cont = 291*((wl1+wl4-wl2-wl3)-(rp1+rp4-rp2-rp3)) inc2.append(inc2cont) else: inc2.append(0) if (column1[3] != 'NaN'): inc1cont = 291*((wl1+wl2-wl3-wl4)-(rp1+rp2-rp3-rp4)) inc1.append(inc1cont) else: inc1.append(0) result = str(secop) + " " + str(inc1cont) + " " + str(inc2cont) +"\n" ffff.write(result) ffff.close()