Ejemplo n.º 1
0
    def readParsHelpFile(self):

        self.tags = {}

        fileLocation = os.path.join(getTopDirectory(), 'data', 'ccp', 'varian',
                                    'parhelp.txt')

        fin = open(fileLocation, 'rU')
        line = fin.readline()

        while line:

            if not (self.patt['emptyline'].search(line)
                    or self.patt['hash'].search(line)):
                cols = line.split()
                if len(cols) < 3 or cols[1] != '=':

                    print "Error parsing following line:" + self.newline + line + self.newline

                else:
                    # Sort out tag
                    tag = cols[0]

                    # Sort out value (remove ' and rejoin with single spaces)
                    value = joinUnquote(cols[2:], "'")

                    self.tags[tag] = value

            line = fin.readline()
Ejemplo n.º 2
0
    def readParsHelpFile(self):

        self.tags = {}

        fileLocation = os.path.join(getTopDirectory(), 'data', 'ccp', 'bruker',
                                    'parhelp.txt')

        fin = open(fileLocation, 'rU')
        line = fin.readline()

        while line:

            if not (self.patt['emptyline'].search(line)
                    or self.patt['hash'].search(line)):
                cols = line.split()
                if len(cols) < 3 or cols[1] != '=':
                    print "Error parsing following line:" + self.newline + line + self.newline
                else:
                    # Sort out tag
                    tag = cols[0]

                    # Sort out value (remove ' and rejoin with single spaces)
                    value = joinUnquote(cols[2:], "'")

                    # Check if multivalue line (eg. SFO1, SFO2, ...)
                    searchobj = self.patt[self.format +
                                          'BracketMultiValue'].search(tag)
                    if searchobj:
                        for i in range(int(searchobj.group(1)),
                                       int(searchobj.group(2)) + 1):
                            curTag = self.patt[self.format +
                                               'BracketMultiValue'].sub(
                                                   str(i), tag)
                            curValue = self.patt[self.format +
                                                 'BracketMultiValue'].sub(
                                                     str(i), value)
                            self.tags[curTag] = curValue
                    else:
                        self.tags[tag] = value

            line = fin.readline()
Ejemplo n.º 3
0
    def read(self, verbose=0, expname='unknown'):

        if verbose == 1:

            print "Reading Varian acquisition parameters file %s" % self.name

        # For reading: Varian parameter stored format is made up of 3 OR MORE lines!
        # See VarianPar class definition for more detailed info.

        fin = open(self.name, 'rU')
        line = fin.readline()

        while line:
            # Checking of empty lines and hashes not really necessary, but left in just in case
            if not (self.patt['emptyline'].search(line)
                    or self.patt['hash'].search(line)):
                cols = line.split()
                if len(cols) != 11:
                    print "  ERROR: %s Varian procpar has wrong number of fields on following line:" % expname + self.newline + line
                elif self.parameters.has_key(cols[0]):
                    print("Reoccuring parameter name: %s" %
                          cols[0]) + self.newline
                else:
                    parname = cols[0]
                    self.parameters[parname] = VarianAcqPar(
                        parname, cols[1], cols[2], cols[3], cols[4], cols[5],
                        cols[6], cols[7], cols[8], cols[9])
                    self.parameters[parname].addHelp(self.parHelp, verbose)

                    # Read values (LINE 2)
                    line = fin.readline()
                    cols = line.split()
                    value_len = returnInt(cols[0])

                    if self.parameters[parname].basictype == 1:
                        # Case real data type
                        self.parameters[parname].addvalues(
                            expname, value_len, returnFloats(cols[1:]))
                    elif self.parameters[parname].basictype == 2:
                        # Case string data type
                        values = []
                        values.append(joinUnquote(cols[1:], '"'))

                        # For multiple line string data, read other lines
                        for value_num in range(1, value_len):
                            # Read values
                            line = fin.readline()
                            cols = line.split()
                            values.append(joinUnquote(cols, '"'))

                        self.parameters[parname].addvalues(
                            expname, value_len, values)

                    else:
                        # Case undefined data type
                        print "  ERROR: %s Varian procpar has undefined basic data type. Check parameter %s." % (
                            expname, parname)

                    # Read enumerations (LAST LINE)
                    line = fin.readline()
                    cols = line.split()
                    enum_len = returnInt(cols[0])

                    if enum_len == 0:
                        self.parameters[parname].addenum(expname, enum_len, '')
                    else:
                        self.parameters[parname].addenum(
                            expname, enum_len, unquote(cols[1:], '"'))

            line = fin.readline()