Changeset 3273

Show
Ignore:
Timestamp:
01/26/12 21:06:58 (4 months ago)
Author:
erkn
Message:

Refactor parameter handling

Location:
branches/mcxtrace-1.0/src/mcrun2
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/mcxtrace-1.0/src/mcrun2/main.py

    r3272 r3273  
    211211    # Run McStas 
    212212    mcstas = McStas(options.instr) 
     213 
     214    # Set parameters 
     215    for param in options.params: 
     216        if '=' in param: 
     217            key, value = param.split('=', 1) 
     218            mcstas.setParameter(key, value) 
     219        else: 
     220            LOG.warning('Ignoring invalid parameter: "%s"', param) 
     221 
    213222    mcstas.prepare(options) 
    214223    mcstas.run() 
  • branches/mcxtrace-1.0/src/mcrun2/mcstas.py

    r3272 r3273  
    7171        self.name = splitext(basename(self.path))[0] 
    7272        self.options = None 
     73        self.params = {} 
    7374 
    7475        # Setup paths 
     
    8182 
    8283 
     84    def setParameter(self, key, value): 
     85        ''' Set the value of an experiment parameter ''' 
     86        self.params[key] = value 
     87 
     88 
    8389    def prepare(self, options): 
    8490        ''' Prepare for simultation run ''' 
     
    8793        # Use mpi? 
    8894        mpi = options.use_mpi 
    89  
    9095        self.binpath += (mpi and '-mpi' or '') 
    9196 
     
    135140 
    136141        # Add parameters last 
    137         args += options.params 
     142        args += [ '%s=%s' % (key, value) for key, value in self.params.items() ] 
    138143 
    139144        # Run McStas