Exemplo n.º 1
0
 def _parseHeader(self, header):
     # DEFINE INSTRUMENT clause
     instr_def, b = header.split('DECLARE')
     d, instr_def = instr_def.split('INSTRUMENT')
     assert d.strip() == 'DEFINE'
     # parameters of instrument
     p = re.compile('\((.*?)\)', re.DOTALL)
     params = p.findall(instr_def)[0]
     params = ''.join([l.strip() for l in params.strip().splitlines()])
     from .McStasComponentParser import McStasComponentParser
     cp = McStasComponentParser()
     params = cp._defParams(params)
     # name of instrumentt
     name, e = instr_def.split('(')
     # INITIALIZE section
     p = re.compile("INITIALIZE\n%{.*%}", re.DOTALL)
     init = p.findall(b)[0]
     init = '\n'.join(init.splitlines()[2:-1])
     return name, params, init
Exemplo n.º 2
0
    def _mcstasParams(self, type):
        """
        Returns list of parameters for McStas component
        
        This includes "DEFINITION PARAMETERS" and "SETTING PARAMETERS"
        Example: [{'type': '', 'name': 'xmin', 'value': '0'}, {'type': '', 'name': 'xmax', 'value': '0'}]
        """
        filename    = self._compPath(type)
        parser      = McStasComponentParser(filename=filename)
        defs        = parser.definitions()
        setparams   = defs.get("setting_parameters")
        defparams   = defs.get("definition_parameters")
        params      = []
        paramlist   = []
        # Can be empty list but not None!
        if (setparams != None) and (defparams != None):
            paramlist   = setparams + defparams

        # Not sure if I need this?
        for p in paramlist:     
            if not self._inParams(p, params):
                params.append(p)

        return params