~madteam/mg5amcnlo/series2.0

« back to all changes in this revision

Viewing changes to madgraph/iolibs/file_writers.py

mwrge with 2.7.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
351
351
        columns. Split in preferential order according to
352
352
        split_characters, and start each new line with line_start."""
353
353
 
354
 
        res_lines = [line]
355
 
 
356
 
        while len(res_lines[-1]) > self.line_length:
 
354
        def get_split_index(line, max_length, max_split, split_characters):
357
355
            split_at = 0
358
356
            for character in split_characters:
359
 
                index = res_lines[-1][(self.line_length - self.max_split): \
360
 
                                      self.line_length].rfind(character)
 
357
                index = line[(max_length - max_split): \
 
358
                                      max_length].rfind(character)
361
359
                if index >= 0:
362
 
                    split_at_tmp = self.line_length - self.max_split + index
 
360
                    split_at_tmp = max_length - max_split + index
363
361
                    if split_at_tmp > split_at:
364
362
                        split_at = split_at_tmp
 
363
            return split_at
 
364
                
 
365
 
 
366
        res_lines = [line]
 
367
 
 
368
        while len(res_lines[-1]) > self.line_length:
 
369
            split_at = get_split_index(res_lines[-1], self.line_length, 
 
370
                                       self.max_split, split_characters)
365
371
            if split_at == 0:
366
 
                split_at = self.line_length
 
372
                split_at = get_split_index(res_lines[-1], self.line_length, 
 
373
                                       self.max_split + 30, split_characters)
 
374
                if split_at == 0:
 
375
                    split_at = self.line_length
367
376
                
368
377
            newline = res_lines[-1][split_at:]
369
378
            nquotes = self.count_number_of_quotes(newline)