@@ -37,12 +37,12 @@ def ContentsValidator(self, filename):
3737 self .formatName = 'Bruker RAW ver. 3'
3838 elif head == 'RAW4.00' :
3939 self .formatName = 'Bruker RAW ver. 4'
40- self .errors += "Sorry, this is a Version 4 Bruker file. "
41- self .errors += "We need documentation for it so that it can be implemented in GSAS-II. "
42- self .errors += "Use PowDLL (http://users.uoi.gr/nkourkou/powdll/) to convert it to ASCII xy."
43- print (self .errors )
44- fp .close ()
45- return False
40+ # self.errors += "Sorry, this is a Version 4 Bruker file. "
41+ # self.errors += "We need documentation for it so that it can be implemented in GSAS-II. "
42+ # self.errors += "Use PowDLL (http://users.uoi.gr/nkourkou/powdll/) to convert it to ASCII xy."
43+ # print(self.errors)
44+ # fp.close()
45+ # return False
4646 else :
4747 self .errors = 'Unexpected information in header: '
4848 if all ([ord (c ) < 128 and ord (c ) != 0 for c in str (head )]): # show only if ASCII
@@ -161,38 +161,93 @@ def Reader(self,filename, ParentFrame=None, **kwarg):
161161 self .repeat = True
162162 fp .close ()
163163
164- elif 'ver. 4' in self .formatName : #does not work - format still elusive
164+ elif 'ver. 4' in self .formatName :
165+ driveNo = 0
165166 fp .seek (12 ) #ok
166- self .comments .append ('Date=' + self .Read (fp ,10 ))
167- self .comments .append ('Time=' + self .Read (fp ,10 ))
168- fp .seek (144 )
169- self .comments .append ('Sample=' + self .Read (fp ,60 ))
170- fp .seek (564 ) # where is it?
171- radius = st .unpack ('<f' ,fp .read (4 ))[0 ]
172- self .comments .append ('Gonio. radius=%.2f' % (radius ))
173- self .Sample ['Gonio. radius' ] = radius
174- fp .seek (516 ) #ok
175- self .comments .append ('Anode=' + self .Read (fp ,4 ))
176- fp .seek (472 ) #ok
177- self .comments .append ('Ka mean=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
178- self .comments .append ('Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
179- self .comments .append ('Ka2=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
180- self .comments .append ('Kb=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
181- self .comments .append ('Ka2/Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
182- fp .seek (pos ) #deliberate fail here - pos not known from file contents
183- self .idstring = os .path .basename (filename ) + ' Scan ' + str (1 )
184- nSteps = int (st .unpack ('<i' ,fp .read (4 ))[0 ])
185- st .unpack ('<d' ,fp .read (8 ))[0 ]
186- start2Th = st .unpack ('<d' ,fp .read (8 ))[0 ]
187- fp .seek (pos + 176 )
188- step = st .unpack ('<d' ,fp .read (8 ))[0 ]
189- pos += headLen #position at start of data block
190- fp .seek (pos )
191- x = np .array ([start2Th + i * step for i in range (nSteps )])
192- y = np .array ([max (1. ,st .unpack ('<f' ,fp .read (4 ))[0 ]) for i in range (nSteps )])
193- w = 1. / y
194- self .powderdata = [x ,y ,w ,np .zeros (nSteps ),np .zeros (nSteps ),np .zeros (nSteps )]
195- fp .close ()
167+ self .comments .append ('Date=' + self .Read (fp ,12 ).strip ('\x00 ' ))
168+ self .comments .append ('Time=' + self .Read (fp ,10 ).strip ('\x00 ' ))
169+ fp .seek (61 ) #start of header segments
170+ while True :
171+ segtype = st .unpack ('<I' ,fp .read (4 ))[0 ]
172+ if not segtype or segtype == 160 :
173+ break # done with header
174+ seglen = max (st .unpack ('<I' ,fp .read (4 ))[0 ],8 )
175+ if segtype == 10 :
176+ fp .read (4 ) #skip these
177+ self .comments .append ('%s=%s' % (self .Read (fp ,24 ).strip ('\x00 ' ),self .Read (fp ,seglen - 36 ).strip ('\x00 ' )))
178+ elif segtype == 30 : #x-ray source info
179+ fp .read (64 )
180+ self .comments .append ('Ka mean=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
181+ self .comments .append ('Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
182+ self .comments .append ('Ka2=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
183+ self .comments .append ('Kb=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
184+ self .comments .append ('Ka2/Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
185+ fp .read (4 )
186+ self .comments .append ('Anode=' + self .Read (fp ,4 ).strip ('\x00 ' ))
187+ fp .read (seglen - 120 )
188+ elif segtype == 60 :
189+ alignFlag = st .unpack ('<I' ,fp .read (4 ))[0 ]
190+ driveName = self .Read (fp ,24 ).strip ('\x00 ' )
191+ fp .read (32 )
192+ Delt = st .unpack ('<d' ,fp .read (8 ))[0 ]
193+ fp .read (seglen - 76 )
194+ self .comments .append ('Drive %s: align flag %d' % (driveName ,alignFlag ))
195+ self .comments .append ('Drive %s: delta %f' % (driveName ,Delt ))
196+ driveNo += 1
197+ else :
198+ fp .read (seglen - 8 )
199+ while (segtype == 0 or segtype == 160 ):
200+ self .idstring = os .path .basename (filename ) # + ' Scan '+str(blockNum)
201+ meta = {}
202+ fp .read (28 )
203+ meta ['ScanType' ] = self .Read (fp ,24 ).strip ('\x00 ' )
204+ if meta ['ScanType' ] not in ['Locked Coupled' ,'Unlocked Coupled' ]:
205+ return False
206+ fp .read (16 )
207+ startAngle = st .unpack ('<d' ,fp .read (8 ))[0 ]
208+ meta ['startAngle' ] = '%.4f' % startAngle
209+ stepSize = st .unpack ('<d' ,fp .read (8 ))[0 ]
210+ meta ['stepSize' ] = '%.4f' % stepSize
211+ Nsteps = st .unpack ('<I' ,fp .read (4 ))[0 ]
212+ meta ['Nsteps' ] = '%d' % Nsteps
213+ meta ['stepTime(ms)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
214+ fp .read (4 )
215+ meta ['generatorVoltage(kV)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
216+ meta ['generatorCurrent(mA)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
217+ fp .read (4 )
218+ meta ['usedWave' ] = st .unpack ('<d' ,fp .read (8 ))[0 ]
219+ fp .read (16 )
220+ datumSize = st .unpack ('<I' ,fp .read (4 ))[0 ]
221+ hdrSize = st .unpack ('<I' ,fp .read (4 ))[0 ]
222+ fp .read (16 )
223+ if meta ['ScanType' ] in ['Locked Coupled' ,'Unlocked Coupled' ]:
224+ while hdrSize > 0 :
225+ segtype = st .unpack ('<I' ,fp .read (4 ))[0 ]
226+ seglen = max (st .unpack ('<I' ,fp .read (4 ))[0 ],8 )
227+ if segtype == 50 :
228+ fp .read (4 )
229+ segName = self .Read (fp ,24 ).strip ('\x00 ' )
230+ if segName in ['Theta' ,'2Theta' ,'Chi' ,'Phi' ,'BeamTranslation' ,'Z-Drive' ,'Divergence Slit' ]:
231+ fp .read (20 )
232+ meta ['start %s' % segName ] = '%.4f' % (st .unpack ('<d' ,fp .read (8 ))[0 ])
233+ fp .read (seglen - 64 )
234+ else :
235+ fp .read (seglen - 36 )
236+ else :
237+ fp .read (seglen - 8 )
238+ hdrSize -= seglen
239+ #end of reading scan header
240+ x = np .array ([startAngle + i * stepSize for i in range (Nsteps )])
241+ y = np .array ([max (1. ,st .unpack ('<f' ,fp .read (4 ))[0 ]) for i in range (Nsteps )])
242+ w = 1. / y
243+ self .powderdata = [x ,y ,w ,np .zeros (Nsteps ),np .zeros (Nsteps ),np .zeros (Nsteps )]
244+ for item in meta :
245+ self .comments .append ('%s = %s' % (item ,str (meta [item ])))
246+ fp .close ()
247+ else :
248+ meta ['Unknown range/scan type' ] = True
249+ fp .read (hdrSize )
250+ fp .read (datumSize * Nsteps )
196251 else :
197252 return False
198253
0 commit comments