#prepare inputs.txt for sw.exe import re #f = open("data/time_series_taoSW1D_wso_CR1888.dat","r") f = open("all.dat","r") lines = f.readlines() rsun = 6.95e5 au = 1.496e8 filename = "inputs.txt" fmt = 'e' with open(filename, "w") as myFile: for i in range(11,len(lines)): x = lines[i].strip() y = re.sub(' +', ' ',x).split(' ') time = float(y[0]) rsrci = float(y[9])*rsun/au rtgti = 1.0 qfi = 0.0 n = float(y[1]) if n < 0 : n = nPrevious t = float(y[2]) if t < 0 : t = tPrevious v = float(y[3]) if v < 0 : v = vPrevious newline = ['',format(time,'.0f'),format(n, fmt),format(t, fmt),format(v, fmt),y[4],y[5],y[6],y[7],y[8],format(rsrci, fmt),y[10],format(rtgti, fmt),y[12],format(qfi, fmt)] myFile.write(' '.join(newline)+'\n') if n > 0 : nPrevious = n if t > 0 : tPrevious = t if v > 0 : vPrevious = v myFile.close() f.close()