Changeset 3369


Ignore:
Timestamp:
May 3, 2018 9:25:40 AM (3 years ago)
Author:
vondreele
Message:

make import Bruker raw python 3 compatible
revise testDeriv & G2strMain to use file names proj.testDeriv instead of testDeriv.dat. That way one ca look at several different derivative examples at once.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrMain.py

    r3318 r3369  
    250250    if DEBUG and IfOK:
    251251#needs: values,HistoPhases,parmDict,varylist,calcControls,pawleyLookup
    252         fl = open('testDeriv.dat','wb')
     252        fl = open(ospath.splitext(GPXfile)[0]+'.testDeriv','wb')
    253253        cPickle.dump(result[0],fl,1)
    254254        cPickle.dump([Histograms,Phases,restraintDict,rigidbodyDict],fl,1)
  • trunk/imports/G2pwd_BrukerRAW.py

    r3136 r3369  
    3434
    3535    # Validate the contents -- make sure we only have valid lines
     36    def Read(self,fp,nbytes):
     37        data = fp.read(nbytes)
     38        if 'bytes' in str(type(data)):
     39            data = data.decode('latin-1')
     40        return data
     41   
    3642    def ContentsValidator(self, filename):
    3743        'Look through the file for expected types of lines in a valid Bruker RAW file'
    3844        fp = open(filename,'rb')
    39         head = fp.read(7)
     45        head = self.Read(fp,7)
     46        if 'bytes' in str(type(head)):
     47            head = head.decode('latin-1')
    4048        if head[:4] == 'RAW ':
    4149            self.formatName = 'Bruker RAW ver. 1'
     
    7482            nBlock = int(st.unpack('<i',fp.read(4))[0])
    7583            fp.seek(168)
    76             self.comments.append('Date/Time='+fp.read(20))
    77             self.comments.append('Anode='+fp.read(2))
     84            self.comments.append('Date/Time='+self.Read(fp,20))
     85            self.comments.append('Anode='+self.Read(fp,2))
    7886            self.comments.append('Ka1=%.5f'%(st.unpack('<f',fp.read(4))[0]))
    7987            self.comments.append('Ka2=%.5f'%(st.unpack('<f',fp.read(4))[0]))
     
    111119            fp.seek(12)
    112120            nBlock = int(st.unpack('<i',fp.read(4))[0])
    113             self.comments.append('Date='+fp.read(10))
    114             self.comments.append('Time='+fp.read(10))
     121            self.comments.append('Date='+self.Read(fp,10))
     122            self.comments.append('Time='+self.Read(fp,10))
    115123            fp.seek(326)
    116             self.comments.append('Sample='+fp.read(60))
     124            self.comments.append('Sample='+self.Read(fp,60))
    117125            fp.seek(564)
    118126            radius = st.unpack('<f',fp.read(4))[0]
     
    120128            self.Sample['Gonio. radius'] = radius
    121129            fp.seek(608)
    122             self.comments.append('Anode='+fp.read(4))
     130            self.comments.append('Anode='+self.Read(fp,4))
    123131            fp.seek(616)
    124132            self.comments.append('Ka mean=%.5f'%(st.unpack('<d',fp.read(8))[0]))
     
    166174        elif 'ver. 4' in self.formatName:   #does not work - format still elusive
    167175            fp.seek(12)   #ok
    168             self.comments.append('Date='+fp.read(10))
    169             self.comments.append('Time='+fp.read(10))
     176            self.comments.append('Date='+self.Read(fp,10))
     177            self.comments.append('Time='+self.Read(fp,10))
    170178            fp.seek(144)
    171             self.comments.append('Sample='+fp.read(60))
     179            self.comments.append('Sample='+self.Read(fp,60))
    172180            fp.seek(564)  # where is it?
    173181            radius = st.unpack('<f',fp.read(4))[0]
     
    175183            self.Sample['Gonio. radius'] = radius
    176184            fp.seek(516)  #ok
    177             self.comments.append('Anode='+fp.read(4))
     185            self.comments.append('Anode='+self.Read(fp,4))
    178186            fp.seek(472)  #ok
    179187            self.comments.append('Ka mean=%.5f'%(st.unpack('<d',fp.read(8))[0]))
  • trunk/testDeriv.py

    r3340 r3369  
    5959        self.testDerivMenu = wx.MenuBar()
    6060        self.File = wx.Menu(title='')
    61         self.File.Append(wxID_FILEOPEN,'Open testDeriv.dat file','Open testDeriv.dat')
     61        self.File.Append(wxID_FILEOPEN,'Open testDeriv file','Open testDeriv')
    6262        self.File.Append(wxID_MAKEPLOTS,'Make plots','Make derivative plots')
    6363        self.File.Append(wxID_FILEEXIT,'Exit','Exit from testDeriv')
     
    8787
    8888    def OnTestRead(self,event):
    89         dlg = wx.FileDialog(self, 'Open testDeriv.dat file',defaultFile='testDeriv.dat',
    90             wildcard='testDeriv.dat')
     89        dlg = wx.FileDialog(self, 'Open *.testDeriv file',defaultFile='*.testDeriv',
     90            wildcard='*.testDeriv')
    9191        if self.dirname:
    9292            dlg.SetDirectory(self.dirname)
Note: See TracChangeset for help on using the changeset viewer.