# Insert a linebreak and character repeatedly into a matrix output which is in fortranForm

Suppose I have a very long string which is a11 element of matrix

a11=2*gopsv-2*Bgopsvw+2*acgmops*v+2*cgmopsv*B-2*acgmopsvB+3*gmopsvB-3*BgmopsvwB+m*w2*B +5*acgm2 +opsvB -ac*m2*w2*B +cgm2*opsvB* - 3*acgmopsv+c*m2-w2*B-acm2-w**2*B....)

etc that goes on for almost 1000 lines. When exported to a .txt file, the file is >100MB. I want to use the expression in Fortan and Fortan will not accept lines greater than 100 characters or so.

To the string x, is it possible to insert a linebreak every 100 characters and insert && at the end of each line and at the beginning of the next line?

i want to do it over the full matrix. it is like first i want to convert matrix elements into FortranForm along with showing them with linebreak character

There's special function for generating fortran-like forms:

SetOptions[\$Output, PageWidth -> 100]
FortranForm[string]


And certainly you can manage string manually. To insert new strings in the string you can write something like this:

string = StringJoin[ToString /@ Range[1000]];

step = 10
StringInsert[string, "&&\n&&", Range[step, StringLength@string, step]]

• Dear Funnypony, my problem is i have a matrix=[a11 a12 a13;a21 a22 a23; so on] i want to show output to be in this format matrix(1,1)=a11 matrix=a12 ...which should be in fortranForm along with continutation character in output at 100 or 200 characters. thers should be "&" operator after say 100 or 200 characters. – Amandeep Nov 9 '14 at 10:56