-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadBinaryCfuns.py
executable file
·200 lines (169 loc) · 7.15 KB
/
ReadBinaryCfuns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
from array import array
import numpy as np
from Params import *
SeekIncSize = 8
ChromaSIS = 16
## Der[igamma , ip , it]
class ReadFSDerCfunPick:
def __init__(self,thisfile,thisMomList,thisDGList):
self.data = []
f = open(thisfile,'rb')
for igd,thisgamma in enumerate(thisDGList):
cmplxflag = False
if 'cmplx' in thisgamma:
cmplxflag = True
thisgamma = thisgamma.replace('cmplx','')
igdloc = DGSet.index(thisgamma)
self.data.append([])
for ip,iploc in enumerate(thisMomList):
self.data[igd].append([])
for it in range(nt):
loc = 2*SeekIncSize*(igdloc + iploc*DGBSize + it*DGBSize*nmom)
if cmplxflag: loc += SeekIncSize
f.seek(loc)
tmpdata = array('d')
tmpdata.read(f,1)
tmpdata.byteswap()
self.data[igd][ip].append(tmpdata[0])
if np.isnan(self.data[igd][ip][it]):
raise NaNCfunError('NaN Values: '+thisgamma+' ' +qvecSet[iploc] + ' it='+str(it+1) )
f.close()
## noDer[igamma , ip , it]
class ReadFSCfunPick:
def __init__(self,thisfile,thisMomList,thisGammaList):
self.data = []
f = open(thisfile,'rb')
for igamma,thisgamma in enumerate(thisGammaList):
cmplxflag = False
if 'cmplx' in thisgamma:
cmplxflag = True
thisgamma = thisgamma.replace('cmplx','')
igammaloc = GammaSet.index(thisgamma)
self.data.append([])
for ip,iploc in enumerate(thisMomList):
self.data[igamma].append([])
for it in range(nt):
loc = 2*SeekIncSize*(igammaloc + iploc*GBSize + it*GBSize*nmom)
if cmplxflag: loc += SeekIncSize
f.seek(loc)
tmpdata = array('d')
tmpdata.read(f,1)
tmpdata.byteswap()
self.data[igamma][ip].append(tmpdata[0])
if np.isnan(self.data[igamma][ip][it]):
if Debug: self.data[igamma][ip][it] = 0.0
raise NaNCfunError('NaN Values: '+thisgamma+ ' ' +qvecSet[iploc] + ' it='+str(it+1) )
f.close()
class Read2ptCfunPick:
def __init__(self,thisfile,thisMomList):
self.data = []
f = open(thisfile,'rb')
for ip,iploc in enumerate(thisMomList):
self.data.append([])
for it in range(nt):
##11 + 22 projected spin component ns = 4 works
loc = SeekIncSize*2*(ns**2)*(it + iploc*nt)
f.seek(loc)
tmpdata = array('d')
tmpdata.read(f,1)
tmpdata.byteswap()
val = tmpdata[0]
f.seek(loc+10*SeekIncSize)
tmpdata = array('d')
tmpdata.read(f,1)
tmpdata.byteswap()
val += tmpdata[0]
self.data[ip].append(val)
if np.isnan(self.data[ip][it]):
raise NaNCfunError('NaN Values: ' +qvecSet[iploc] + ' it='+str(it+1) )
# if 'cmplx' in RI:
# self.datai[ipread].append(tmpdata[loc+1]+tmpdata[loc+11])
if self.data[ip][tsource-1] < 0.0:
self.data[ip] = np.negative(self.data[ip])
f.close()
class Read2ptCfunChroma:
def __init__(self,thisfile,thisMomList):
##CURRENT: LIME_UNPACK THE FILE AND READ THE BINARY INSIDE##
self.data = []
barnum = 0
# barnum = 21
for ip,iploc in enumerate(thisMomList):
self.data.append(np.memmap(thisfile,dtype=np.complex128,mode='r',offset=nt*ChromaSIS*ip,shape=(nt,)).byteswap())
class NaNCfunError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
# ## Der[igamma , ip , it]
# class ReadFSDerCfunPick:
# def __init__(self,file,thisMomList,thisDGList):
# self.data = []
# f = open(file,'rb')
# tmpdata = array('d')
# tmpdata.read(f,DGBSize*nmom*nt*2)
# tmpdata.byteswap()
# for igd,thisgamma in enumerate(thisDGList):
# cmplxflag = False
# if 'cmplx' in thisgamma:
# cmplxflag = True
# thisgamma = thisgamma.replace('cmplx','')
# igdloc = DGSet.index(thisgamma)
# self.data.append([])
# for ip,iploc in enumerate(thisMomList):
# self.data[igd].append([])
# for it in range(nt):
# loc = igdloc*2 + iploc*DGBSize*2 + it*DGBSize*nmom*2
# if cmplxflag: loc += 1
# self.data[igd][ip].append(tmpdata[loc])
# if np.isnan(self.data[igd][ip][it]):
# raise NaNCfunError('NaN Values: '+thisgamma+' ' +qvecSet[iploc] + ' it='+str(it+1) )
# f.close()
# ## noDer[igamma , ip , it]
# class ReadFSCfunPick:
# def __init__(self,file,thisMomList,thisGammaList):
# self.data = []
# f = open(file,'rb')
# tmpdata = array('d')
# try:
# tmpdata.read(f,GBSize*nmom*nt*2)
# except:
# print file
# tmpdata.byteswap()
# for igamma,thisgamma in enumerate(thisGammaList):
# cmplxflag = False
# if 'cmplx' in thisgamma:
# cmplxflag = True
# thisgamma = thisgamma.replace('cmplx','')
# igammaloc = GammaSet.index(thisgamma)
# self.data.append([])
# for ip,iploc in enumerate(thisMomList):
# self.data[igamma].append([])
# for it in range(nt):
# loc = igammaloc*2 + iploc*GBSize*2 + it*GBSize*nmom*2
# if cmplxflag: loc += 1
# self.data[igamma][ip].append(tmpdata[loc])
# if np.isnan(self.data[igamma][ip][it]):
# raise NaNCfunError('NaN Values: '+thisgamma+ ' ' +qvecSet[iploc] + ' it='+str(it+1) )
# f.close()
# ##[ip,it]
# class Read2ptCfunPickOld:
# def __init__(self,file,thisMomList):
# self.data = []
# f = open(file,'rb')
# tmpdata = array('d')
# tmpdata.read(f,nmom*ns*ns*nt*2)
# tmpdata.byteswap()
# for ip,iploc in enumerate(thisMomList):
# self.data.append([])
# for it in range(nt):
# ##11 + 22 projected spin component ns = 4 works
# loc = it*2*ns**2 + iploc*nt*2*ns**2
# self.data[ip].append(tmpdata[loc]+tmpdata[loc+10])
# if np.isnan(self.data[ip][it]):
# raise NaNCfunError('NaN Values: ' +qvecSet[iploc] + ' it='+str(it+1) )
# # if 'cmplx' in RI:
# # self.datai[ipread].append(tmpdata[loc+1]+tmpdata[loc+11])
# if self.data[ip][tsource-1] < 0.0:
# self.data[ip] = np.negative(self.data[ip])
# f.close()