Changeset 1168 for trunk/GSASII.py
- Timestamp:
- Dec 16, 2013 10:43:01 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r1160 r1168 297 297 self.lastimport = '' 298 298 self.zipfile = None 299 singlereader = True 299 300 if reader is None: 301 singlereader = False 300 302 multiple = False 301 303 #print "use all formats" … … 372 374 primaryReaders = [] 373 375 secondaryReaders = [] 374 for r in readerlist:375 flag = r .ExtensionValidator(filename)376 for rd in readerlist: 377 flag = rd.ExtensionValidator(filename) 376 378 if flag is None: 377 secondaryReaders.append(r )379 secondaryReaders.append(rd) 378 380 elif flag: 379 primaryReaders.append(r )381 primaryReaders.append(rd) 380 382 if len(secondaryReaders) + len(primaryReaders) == 0: 381 383 self.ErrorDialog('No Format','No matching format for file '+filename) … … 412 414 self.lastimport = filename 413 415 # try the file first with Readers that specify the 414 # file s extension and later with ones thatallow it415 flag = False416 # file's extension and later with ones that merely allow it 417 errorReport = '' 416 418 for rd in primaryReaders+secondaryReaders: 417 try: 419 fp.seek(0) # rewind 420 rd.errors = "" # clear out any old errors 421 if not rd.ContentsValidator(fp): # rejected on cursory check 422 errorReport += "\n "+rd.formatName + ' validator error' 423 if rd.errors: 424 errorReport += ': '+rd.errors 425 continue 426 repeat = True 427 rdbuffer = {} # create temporary storage for file reader 428 block = 0 429 while repeat: # loop if the reader asks for another pass on the file 430 block += 1 431 repeat = False 418 432 fp.seek(0) # rewind 419 if not rd.ContentsValidator(fp): continue # rejected on cursory check 420 repeat = True 421 rdbuffer = {} # create temporary storage for file reader 422 block = 0 423 while repeat: 424 block += 1 425 repeat = False 426 fp.seek(0) # rewind 427 rd.objname = os.path.basename(filename) 433 rd.objname = os.path.basename(filename) 434 flag = False 435 try: 428 436 flag = rd.Reader(filename,fp,self, 429 437 buffer=rdbuffer, … … 431 439 usedRanIdList=usedRanIdList, 432 440 ) 433 if flag: 434 rd_list.append(copy.deepcopy(rd)) # success 435 if rd.repeat: repeat = True 436 except: 437 import traceback 438 print traceback.format_exc() 439 msg += '\nError reading file '+filename+' with format '+ rd.formatName 440 #self.ErrorDialog('Read Error', 441 # 'Error reading file '+filename 442 # +' with format '+ rd.formatName) 443 continue 444 if flag: 441 except rd.ImportException as detail: 442 rd.errors += "\n Read exception: "+str(detail) 443 except Exception as detail: 444 rd.errors += "\n Unhandled read exception: "+str(detail) 445 rd.errors += "\n Traceback info:\n"+str(traceback.format_exc()) 446 if flag: # this read succeeded 447 rd_list.append(copy.deepcopy(rd)) # save the result before it is written over 448 if rd.repeat: 449 repeat = True 450 continue 451 errorReport += '\n'+rd.formatName + ' read error' 452 if rd.errors: 453 errorReport += ': '+rd.errors 454 if rd_list: # read succeeded, was there a warning or any errors? 445 455 if rd.warnings: 446 456 self.ErrorDialog('Read Warning','The '+ rd.formatName+ 447 457 ' reader reported a warning message:\n\n'+ 448 458 rd.warnings) 449 break # success reading459 break # success in reading, try no further 450 460 else: 451 if reader:461 if singlereader: 452 462 self.ErrorDialog('Read Error','The '+ rd.formatName+ 453 ' reader was not able to read file '+filename+msg) 463 ' reader was not able to read file '+filename+msg+ 464 '\n\nError message(s):\n'+errorReport 465 ) 454 466 else: 455 self.ErrorDialog('Read Error','No reader is able to read file '+filename+msg) 467 self.ErrorDialog('Read Error','No reader was able to read file '+filename+msg+ 468 '\n\nError messages:\n'+errorReport 469 ) 456 470 except: 457 471 import traceback 458 472 print traceback.format_exc() 459 self.ErrorDialog('Open Error',' Error on open offile '+filename)473 self.ErrorDialog('Open Error','Unexpected error trying to open or read file '+filename) 460 474 if fp: fp.close() 461 475 return rd_list … … 581 595 dlg.Destroy() 582 596 print 'Read structure factor table '+str(HistName)+' from file '+str(self.lastimport) 597 if not rd.RefDict['FF']: 598 rd.RefDict['FF'] = [{} for i in range(len(rd.RefDict['RefList']))] 583 599 Id = self.PatternTree.AppendItem(parent=self.root, 584 600 text='HKLF '+HistName)
Note: See TracChangeset
for help on using the changeset viewer.