Ignore:
Timestamp:
Mar 24, 2014 5:22:41 PM (8 years ago)
Author:
toby
Message:

reorg exports to implement directory selection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/exports/G2export_map.py

    r1123 r1261  
    5353        # load all of the tree into a set of dicts
    5454        self.loadTree()
    55         if self.ExportSelect( # set export parameters
    56             AskFile=True          # prompt the user for a file name
    57             ): return
     55        if self.ExportSelect(): return  # set export parameters, get file name
     56        filename = self.filename
    5857        for phasenam in self.phasenam:
    5958            phasedict = self.Phases[phasenam] # pointer to current phase info           
    6059            rho = phasedict['General']['Map'].get('rho',[])
    6160            if not len(rho):
    62                 return
    63             print self.filename
    64             self.OpenFile(self.filename)
     61                print "There is no map for phase "+str(phasenam)
     62                continue
     63            if len(self.phasenam) > 1: # if more than one filename is written, add a phase # -- not in use yet
     64                i = self.Phases[phasenam]['pId']
     65                self.filename = os.path.splitext(filename)[1] + "_" + mapData['MapType'] + str(i) + self.extension
     66            self.OpenFile()
    6567            self.Write("Map of Phase "+str(phasenam)+" from "+str(self.G2frame.GSASprojectfile))
    6668            # get cell parameters & print them
     
    7476                    for k in range(nz):
    7577                        self.Write(str(rho[i,j,k]))
    76             print('map from Phase '+str(phasenam)+' written to file '+str(self.filename))
    7778            self.CloseFile()
    78             return
     79            print('map from Phase '+str(phasenam)+' written to file '+str(self.fullpath))
    7980
    8081class ExportMapCCP4(G2IO.ExportBaseclass):
     
    9495
    9596    # Tools for file writing.
    96     def OpenFile(self,fil=None):
    97         '''Open the output file as binary
    98 
    99         :param str fil: The name of the file to open. If None (default)
    100           the name defaults to self.filename.
    101         :returns: the file object opened by the routine which is also
    102           saved as self.fp
    103         '''
    104         if not fil:
    105             fil = self.filename
    106         self.fp = open(fil,'wb')
    107         return self.fp
    108        
    10997    def Write(self,data,dtype):
    11098        import struct
     
    122110        # load all of the tree into a set of dicts
    123111        self.loadTree()
    124         if self.ExportSelect( # set export parameters
    125             AskFile=False     # I'll make the file name
    126             ): return
     112        if self.ExportSelect(): return  # set export parameters, get file name
     113        filename = self.filename
    127114        for phasenam in self.phasenam:
    128115            phasedict = self.Phases[phasenam] # pointer to current phase info
     
    131118           
    132119            if not len(rho):
    133                 return
     120                print "There is no map for phase "+str(phasenam)
     121                continue
     122            if len(self.phasenam) > 1: # if more than one filename is written, add a phase # -- not in use yet
     123                i = self.Phases[phasenam]['pId']
     124                self.filename = os.path.splitext(filename)[1] + "_" + mapData['MapType'] + str(i) + self.extension
    134125            cell = phasedict['General']['Cell'][1:7]
    135126            nx,ny,nz = rho.shape
    136             filename,ext = os.path.splitext(self.filename)
    137             self.filename = filename+'_'+phasenam+'_'+mapData['MapType']+ext
    138             self.OpenFile(self.filename)
     127            self.OpenFile(mode='wb')
    139128            for n in rho.shape: self.Write(n,'i')  #nX,nY,nZ
    140129            self.Write(2,'i')           #mode=2 float map
     
    156145            for x in rho.flatten('F'):
    157146                self.Write(x,'f')
    158             print('map from Phase '+str(phasenam)+' written to file '+str(self.filename))
    159147            self.CloseFile()
    160             return
     148            print('map from Phase '+str(phasenam)+' written to file '+str(self.fullpath))
Note: See TracChangeset for help on using the changeset viewer.