Changeset 1446


Ignore:
Timestamp:
Jul 30, 2014 11:36:23 AM (7 years ago)
Author:
vondreele
Message:

add new import routine for JANA2000 single xtal files from ISIS

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1399 r1446  
    16361636        ImportBaseclass.ReInitialize(self)
    16371637        self.InitParameters()
     1638        self.Banks = []             #for multi bank data (usually TOF)
    16381639        self.RefDict = {'RefList':[],'FF':[]}
    16391640       
  • trunk/imports/G2sfact.py

    r1391 r1446  
    2525    l = filepointer.readline()
    2626    line = 1
    27     while '#' in l[0]:        #get past comments, if any
     27    while l[0] in ['#','(']:        #get past comments & fortran formats, if any
    2828        l = filepointer.readline()       
    2929        line += 1
     
    3333            parent.errors = 'line '+str(line)+': invalid input\n'+l
    3434            return False
    35         for v in S:
     35        for v in S[:nCol]:
    3636            try:
    3737                float(v)
     
    187187            return False
    188188
     189class NT_JANA2K_ReaderClass(G2IO.ImportStructFactor):
     190    'Routines to import neutron TOF F**2, sig(F**2) reflections from a JANA2000 file'
     191    def __init__(self):
     192        super(self.__class__,self).__init__( # fancy way to self-reference
     193            extensionlist=('.int','.INT'),
     194            strictExtension=False,
     195            formatName = u'Neutron TOF JANA2000 F\u00b2',
     196            longFormatName = u'Neutron TOF [hkl, Fo\u00b2, sig(Fo\u00b2),...] Structure factor text file'
     197            )
     198
     199    def ContentsValidator(self, filepointer):
     200        'Make sure file contains the expected columns on numbers & count number of data blocks - "Banks"'
     201        oldNo = -1
     202        for line,S in enumerate(filepointer):
     203            if not S:   #empty line terminates read
     204                break
     205            if S[0] in ['#','(']: continue       #ignore comments & fortran format line
     206            bankNo = S.split()[5]
     207            if bankNo != oldNo:
     208                self.Banks.append({'RefDict':{'RefList':[],}})
     209                oldNo = bankNo
     210        filepointer.seek(0)
     211        return ColumnValidator(self, filepointer,nCol=10)
     212
     213    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
     214        'Read the file'
     215        filepointer.seek(0)
     216        try:
     217            for line,S in enumerate(filepointer):
     218                self.errors = '  Error reading line '+str(line+1)
     219                if S[0] in ['#','(']: continue       #ignore comments & fortran format line
     220                data = S.split()
     221                h,k,l,Fo,sigFo,bN,wave,x,x,tbar = data[:10]  #bN = 1..., 6 dir cos next                   
     222                h,k,l = [int(h),int(k),int(l)]
     223                if not any([h,k,l]):
     224                    break
     225                Fo = float(Fo)
     226                sigFo = float(sigFo)
     227                wave = float(wave)
     228                tbar = float(tbar)
     229                if len(self.Banks):
     230                    self.Banks[int(bN)-1]['RefDict']['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar])
     231                else:
     232                # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
     233                    self.RefDict['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar])
     234            if len(self.Banks):
     235                self.UpdateParameters(Type='SNT',Wave=None) # histogram type
     236                for Bank in self.Banks:
     237                    Bank['RefDict']['RefList'] = np.array(Bank['RefDict']['RefList'])                   
     238            else:
     239                self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
     240                self.errors = 'Error after reading reflections (unexpected!)'
     241                self.UpdateParameters(Type='SNT',Wave=None) # histogram type
     242            return True
     243        except Exception as detail:
     244            self.errors += '\n  '+str(detail)
     245            print '\n\n'+self.formatName+' read error: '+str(detail) # for testing
     246            import traceback
     247            traceback.print_exc(file=sys.stdout)
     248            return False
     249
Note: See TracChangeset for help on using the changeset viewer.