@@ -37,12 +37,13 @@ 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+ pwdrscan = fp .read ()
41+ nBanks = pwdrscan .count (b'2Theta' )
42+ if not len (self .selections ):
43+ self .selections = list (range (nBanks ))
44+ self .numbanks = nBanks
45+ for i in range (nBanks ):
46+ self .dnames .append (os .path .basename (filename )+ ' scan ' + (str (i )))
4647 else :
4748 self .errors = 'Unexpected information in header: '
4849 if all ([ord (c ) < 128 and ord (c ) != 0 for c in str (head )]): # show only if ASCII
@@ -167,89 +168,105 @@ def Reader(self,filename, ParentFrame=None, **kwarg):
167168 self .comments .append ('Date=' + self .Read (fp ,12 ).strip ('\x00 ' ))
168169 self .comments .append ('Time=' + self .Read (fp ,10 ).strip ('\x00 ' ))
169170 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 ]))
171+ nBank = 0
172+ blockNum = kwarg .get ('blocknum' ,0 )
173+ while nBank < self .numbanks :
174+ while True : #read block header
175+ segtype = st .unpack ('<I' ,fp .read (4 ))[0 ]
176+ if not segtype or segtype == 160 :
177+ break # done with header
178+ seglen = max (st .unpack ('<I' ,fp .read (4 ))[0 ],8 )
179+ if segtype == 10 :
180+ fp .read (4 ) #skip these
181+ self .comments .append ('%s=%s' % (self .Read (fp ,24 ).strip ('\x00 ' ),self .Read (fp ,seglen - 36 ).strip ('\x00 ' )))
182+ elif segtype == 30 : #x-ray source info
183+ fp .read (64 )
184+ self .comments .append ('Ka mean=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
185+ self .comments .append ('Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
186+ self .comments .append ('Ka2=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
187+ self .comments .append ('Kb=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
188+ self .comments .append ('Ka2/Ka1=%.5f' % (st .unpack ('<d' ,fp .read (8 ))[0 ]))
189+ fp .read (4 )
190+ self .comments .append ('Anode=' + self .Read (fp ,4 ).strip ('\x00 ' ))
191+ fp .read (seglen - 120 )
192+ elif segtype == 60 :
193+ alignFlag = st .unpack ('<I' ,fp .read (4 ))[0 ]
194+ driveName = self .Read (fp ,24 ).strip ('\x00 ' )
195+ fp .read (32 )
196+ Delt = st .unpack ('<d' ,fp .read (8 ))[0 ]
197+ fp .read (seglen - 76 )
198+ self .comments .append ('Drive %s: align flag %d' % (driveName ,alignFlag ))
199+ self .comments .append ('Drive %s: delta %f' % (driveName ,Delt ))
200+ driveNo += 1
201+ else :
202+ fp .read (seglen - 8 )
203+ if (segtype == 0 or segtype == 160 ): #read data block
204+ self .idstring = self .dnames [nBank ]
205+ meta = {}
206+ fp .read (28 )
207+ meta ['ScanType' ] = self .Read (fp ,24 ).strip ('\x00 ' )
208+ if meta ['ScanType' ] not in ['Locked Coupled' ,'Unlocked Coupled' ,'Detector Scan' ]:
209+ return False
210+ fp .read (16 )
211+ startAngle = st .unpack ('<d' ,fp .read (8 ))[0 ]
212+ meta ['startAngle' ] = '%.4f' % startAngle
213+ stepSize = st .unpack ('<d' ,fp .read (8 ))[0 ]
214+ meta ['stepSize' ] = '%.4f' % stepSize
215+ Nsteps = st .unpack ('<I' ,fp .read (4 ))[0 ]
216+ meta ['Nsteps' ] = '%d' % Nsteps
217+ meta ['stepTime(ms)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
185218 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 )
219+ meta ['generatorVoltage(kV)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
220+ meta ['generatorCurrent(mA)' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
221+ fp .read (4 )
222+ meta ['usedWave' ] = st .unpack ('<d' ,fp .read (8 ))[0 ]
223+ fp .read (16 )
224+ datumSize = st .unpack ('<I' ,fp .read (4 ))[0 ]
225+ hdrSize = st .unpack ('<I' ,fp .read (4 ))[0 ]
226+ fp .read (16 )
227+ if meta ['ScanType' ] in ['Locked Coupled' ,'Unlocked Coupled' ,'Detector Scan' ]:
228+ while hdrSize > 0 :
229+ segtype = st .unpack ('<I' ,fp .read (4 ))[0 ]
230+ seglen = max (st .unpack ('<I' ,fp .read (4 ))[0 ],8 )
231+ if segtype == 50 :
232+ fp .read (4 )
233+ segName = self .Read (fp ,24 ).strip ('\x00 ' )
234+ if segName in ['Theta' ,'2Theta' ,'Chi' ,'Phi' ,'BeamTranslation' ,'Z-Drive' ,'Divergence Slit' ]:
235+ fp .read (20 )
236+ meta ['start %s' % segName ] = '%.4f' % (st .unpack ('<d' ,fp .read (8 ))[0 ])
237+ fp .read (seglen - 64 )
238+ else :
239+ fp .read (seglen - 36 )
234240 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 )
241+ fp .read (seglen - 8 )
242+ hdrSize -= seglen
243+ #end of reading scan header
244+ pos = fp .tell ()
245+ fp .seek (pos - 16 )
246+ meta ['Temperature' ] = st .unpack ('<f' ,fp .read (4 ))[0 ]
247+ if meta ['Temperature' ] > 7. : #one raw4 file had int4='9999' in this place & <7K unlikely for lab data
248+ self .Sample ['Temperature' ] = meta ['Temperature' ]
249+ self .Sample ['Omega' ] = meta ['start Theta' ]
250+ fp .read (12 )
251+ x = np .array ([startAngle + i * stepSize for i in range (Nsteps )])
252+ y = np .array ([max (1. ,st .unpack ('<f' ,fp .read (4 ))[0 ]) for i in range (Nsteps )])
253+ w = 1. / y
254+ if nBank == blockNum - 1 :
255+ self .powderdata = [x ,y ,w ,np .zeros (Nsteps ),np .zeros (Nsteps ),np .zeros (Nsteps )]
256+ for item in meta :
257+ self .comments .append ('%s = %s' % (item ,str (meta [item ])))
258+ fp .close ()
259+ self .repeat = True
260+ if nBank == self .numbanks - 1 :
261+ self .repeat = False
262+ return True
263+ else :
264+ meta ['Unknown range/scan type' ] = True
265+ fp .read (hdrSize )
266+ fp .read (datumSize * Nsteps )
267+ nBank += 1
251268 else :
252269 return False
253-
270+ self . repeat = False
254271 return True
255272
0 commit comments