source: trunk/imports/G2phase_GPX.py @ 614

Last change on this file since 614 was 614, checked in by toby, 10 years ago

import GSAS powder data tested; import routines moved to imports

File size: 2.1 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2012-02-13 11:33:35 -0600 (Mon, 13 Feb 2012) $
4# $Author: vondreele & toby $
5# $Revision: 482 $
6# $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/G2importphase_GPX.py $
7# $Id: G2importphase_GPX.py 482 2012-02-13 17:33:35Z vondreele $
8########### SVN repository information ###################
9# Routines to import Phase information from GSAS-II .gpx files
10import cPickle
11import GSASIIIO as G2IO
12import GSASIIstruct as G2str
13
14class PhaseReaderClass(G2IO.ImportPhase):
15    def __init__(self):
16        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
17            extensionlist=('.gpx',),
18            strictExtension=True,
19            formatName = 'GSAS-II gpx',
20            longFormatName = 'GSAS-II project (.gpx file) import'
21            )
22    def ContentsValidator(self, filepointer):
23        # if the 1st section can't be read as a cPickle file, it can't be!
24        try: 
25            cPickle.load(filepointer)
26        except:
27            return False
28        return True
29    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
30        try:
31            phasenames = G2str.GetPhaseNames(filename)
32            print phasenames
33        except:
34            return False
35        if not phasenames:
36            return False            # no blocks with coordinates
37        elif len(phasenames) == 1: # no choices
38            selblk = 0
39        else:                       # choose from options               
40            selblk = self.PhaseSelector(
41                phasenames,
42                ParentFrame=ParentFrame,
43                title= 'Select a phase from the list below',
44                )
45            if selblk is None: return False # User pressed cancel
46        try:
47            self.Phase = G2str.GetAllPhaseData(filename,phasenames[selblk])
48            return True
49        except Exception as detail:
50            print self.formatName+' error:',detail # for testing
51            print sys.exc_info()[0] # for testing
52            import traceback
53            print traceback.format_exc()
Note: See TracBrowser for help on using the repository browser.