This will let the line wrapping function respect settings of the fortran
printer.
---
 sympy/printing/fcode.py            |  107 ++++++++++++++++++------------------
 sympy/printing/tests/test_fcode.py |    5 +-
 2 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/sympy/printing/fcode.py b/sympy/printing/fcode.py
index fb17412..913f4e5 100644
--- a/sympy/printing/fcode.py
+++ b/sympy/printing/fcode.py
@@ -93,7 +93,7 @@ def doprint(self, expr):
             for name, value in number_symbols:
                 lines.append("      parameter (%s = %s)" % (name, value))
             lines.extend(text.split("\n"))
-            lines = wrap_fortran(lines)
+            lines = self._wrap_fortran(lines)
             result = "\n".join(lines)
         else:
             result = number_symbols, self._not_fortran, text
@@ -229,68 +229,67 @@ def _print_not_fortran(self, expr):
     _print_Wild = _print_not_fortran
     _print_WildFunction = _print_not_fortran
 
-
-def wrap_fortran(lines):
-    """Wrap long Fortran lines
-
-       Argument:
-         lines  --  a list of lines (without \\n character)
-
-       A comment line is split at white space. Code lines are split with a more
-       complex rule to give nice results.
-    """
-    # routine to find split point in a code line
-    my_alnum = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")
-    my_white = set(" \t()")
-    def split_pos_code(line, endpos):
-        if len(line) <= endpos:
-            return len(line)
-        pos = endpos
-        split = lambda pos: \
-            (line[pos] in my_alnum and line[pos-1] not in my_alnum) or \
-            (line[pos] not in my_alnum and line[pos-1] in my_alnum) or \
-            (line[pos] in my_white and line[pos-1] not in my_white) or \
-            (line[pos] not in my_white and line[pos-1] in my_white)
-        while not split(pos):
-            pos -= 1
-            if pos == 0:
-                return endpos
-        return pos
-    # split line by line and add the splitted lines to result
-    result = []
-    for line in lines:
-        if line.startswith("      "):
-            # code line
-            pos = split_pos_code(line, 72)
-            hunk = line[:pos].rstrip()
-            line = line[pos:].lstrip()
-            result.append(hunk)
-            while len(line) > 0:
-                pos = split_pos_code(line, 65)
+    def _wrap_fortran(self, lines):
+        """Wrap long Fortran lines
+
+           Argument:
+             lines  --  a list of lines (without \\n character)
+
+           A comment line is split at white space. Code lines are split with a 
more
+           complex rule to give nice results.
+        """
+        # routine to find split point in a code line
+        my_alnum = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")
+        my_white = set(" \t()")
+        def split_pos_code(line, endpos):
+            if len(line) <= endpos:
+                return len(line)
+            pos = endpos
+            split = lambda pos: \
+                (line[pos] in my_alnum and line[pos-1] not in my_alnum) or \
+                (line[pos] not in my_alnum and line[pos-1] in my_alnum) or \
+                (line[pos] in my_white and line[pos-1] not in my_white) or \
+                (line[pos] not in my_white and line[pos-1] in my_white)
+            while not split(pos):
+                pos -= 1
+                if pos == 0:
+                    return endpos
+            return pos
+        # split line by line and add the splitted lines to result
+        result = []
+        for line in lines:
+            if line.startswith("      "):
+                # code line
+                pos = split_pos_code(line, 72)
                 hunk = line[:pos].rstrip()
                 line = line[pos:].lstrip()
-                result.append("     @ %s" % hunk)
-        elif line.startswith("C"):
-            # comment line
-            if len(line) > 72:
-                pos = line.rfind(" ", 6, 72)
-                if pos == -1:
-                    pos = 72
-                hunk = line[:pos]
-                line = line[pos:].lstrip()
                 result.append(hunk)
                 while len(line) > 0:
-                    pos = line.rfind(" ", 0, 66)
+                    pos = split_pos_code(line, 65)
+                    hunk = line[:pos].rstrip()
+                    line = line[pos:].lstrip()
+                    result.append("     @ %s" % hunk)
+            elif line.startswith("C"):
+                # comment line
+                if len(line) > 72:
+                    pos = line.rfind(" ", 6, 72)
                     if pos == -1:
-                        pos = 66
+                        pos = 72
                     hunk = line[:pos]
                     line = line[pos:].lstrip()
-                    result.append("C     %s" % hunk)
+                    result.append(hunk)
+                    while len(line) > 0:
+                        pos = line.rfind(" ", 0, 66)
+                        if pos == -1:
+                            pos = 66
+                        hunk = line[:pos]
+                        line = line[pos:].lstrip()
+                        result.append("C     %s" % hunk)
+                else:
+                    result.append(line)
             else:
                 result.append(line)
-        else:
-            result.append(line)
-    return result
+        return result
 
 
 def fcode(expr, **settings):
diff --git a/sympy/printing/tests/test_fcode.py 
b/sympy/printing/tests/test_fcode.py
index 7884387..1271c84 100644
--- a/sympy/printing/tests/test_fcode.py
+++ b/sympy/printing/tests/test_fcode.py
@@ -3,7 +3,7 @@
 from sympy import Catalan, EulerGamma, E, GoldenRatio, I, pi
 from sympy import Function, Rational, Integer
 
-from sympy.printing.fcode import fcode, wrap_fortran
+from sympy.printing.fcode import fcode, FCodePrinter
 
 
 def test_printmethod():
@@ -159,6 +159,7 @@ def test_fcode_Piecewise():
 
 def test_wrap_fortran():
     #   
"########################################################################"
+    printer = FCodePrinter()
     lines = [
         "C     This is a long comment on a single line that must be wrapped 
properly",
         "      this = is + a + long + and + nasty + fortran + statement + that 
* must + be + wrapped + properly",
@@ -176,7 +177,7 @@ def test_wrap_fortran():
         "      this = is + a + long + and + nasty + fortran + 
statement(that)/must + be + wrapped + properly",
         "      this = is + a + long + and + nasty + fortran +     
statement(that)/must + be + wrapped + properly",
     ]
-    wrapped_lines = wrap_fortran(lines)
+    wrapped_lines = printer._wrap_fortran(lines)
     expected_lines = [
         "C     This is a long comment on a single line that must be wrapped",
         "C     properly",
-- 
1.6.5

-- 
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patc...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en.

Reply via email to