Question: Maple corrupts string larger than one million when writing to file.

Maple 2017.1 on windows 7.

This is VERY frustrating. If I have a string which is too long (do not blame me, it is Maple's output), and  try to save it to text file using fprintf(), then Maple decides to insert CARRIAGE RETURN at about each 1,000,000 characters intervals. 

So if the string happened to be 5 million chars, and instead of getting one long line in the file for this one result, It writes 5 lines in the file.

Becuase of this, I can't postprocess this output, since the program that reads the file expects one line per one result. So it fails to parse it. And having to post process the file to correct this is not easy at all.

Why is there a limitation of writing long string to a file without it being chopped of like this? Is there a way to work around this? Here is a MWE

 

restart;
directory("C:\\bug");
result:=int((a+b*tan(e*x+d)+c*tan(e*x+d)^2)^(1/2)*tan(e*x+d)^2,x):
result_as_string:=convert(result,string):
fd := fopen("out.txt",WRITE):
fprintf(fd,"%s\n",result_as_string);
fclose(fd);

As you can see, I wrote the result as one string. Now if you look at the file out.txt in the directory (you might want to use good editor for this, such as vi or textedit), you will see many lines in there, and not one long line as expected. Or you can run this code

restart;
directory("C:\\bug");
number_of_lines :=0:
line:=readline("out.txt"):
while line <>0 do
   number_of_lines :=number_of_lines + 1:
   line:=readline("out.txt"):
od:
print(` number of lines read is `,number_of_lines);

The above gives

                ` number of lines read is `, 24

This problem now means I am not able to continue with what I am doing. Does this happen on other platforms?

I think this happens due to Maple limits

      `[Length of output exceeds limit of 1000000]`

However, I am NOT dispalying anything on the screen. This is all going to text files.  It seems Maple output limits of 1,000,000 is confusing fprintf() to a file as well?

Please Wait...