Changeset 3811 for trunk/GSASIIstrIO.py


Ignore:
Timestamp:
Feb 4, 2019 3:35:43 PM (3 years ago)
Author:
toby
Message:

scriptable: fix reading py2 gpx in py3 & use of multi-set instprm files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIstrIO.py

    r3803 r3811  
    4949       return cPickle.load(fp,encoding='latin-1')
    5050
     51def GetFullGPX(GPXfile):
     52    ''' Returns complete contents of GSASII gpx file
     53
     54    :param str GPXfile: full .gpx file name
     55    :returns: Project,nameList, where
     56
     57      * Project (dict) is a representation of gpx file following the GSAS-II tree structure
     58        for each item: key = tree name (e.g. 'Controls','Restraints',etc.), data is dict
     59        data dict = {'data':item data whch may be list, dict or None,'subitems':subdata (if any)}
     60      * nameList (list) has names of main tree entries & subentries used to reconstruct project file
     61    '''
     62    fp = open(GPXfile,'rb')
     63    Project = {}
     64    nameList = []
     65    try:
     66        while True:
     67            try:
     68                data = cPickleLoad(fp)
     69            except EOFError:
     70                break
     71            datum = data[0]
     72            Project[datum[0]] = {'data':datum[1]}
     73            nameList.append([datum[0],])
     74            for datus in data[1:]:
     75                Project[datum[0]][datus[0]] = datus[1]
     76                nameList[-1].append(datus[0])
     77        # print('project load successful')
     78    except Exception as msg:
     79        print('Read Error:',msg)
     80        raise Exception("Error reading file "+str(GPXfile)+". This is not a GSAS-II .gpx file")
     81    finally:
     82        fp.close()
     83    return Project,nameList
     84   
    5185def GetControls(GPXfile):
    5286    ''' Returns dictionary of control items found in GSASII gpx file
Note: See TracChangeset for help on using the changeset viewer.