Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / Maple / June 2009



Tip: Looking for answers? Try searching our database.

C(++) source to write an m-file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Helmut Jarausch - 28 Jun 2009 11:10 GMT
Hi,

I have a (big) matrix computed by a C++ program.
I'd like to write the data from within that program to a (binary) file (a Maple m-file)
which can be read by Maple for further processing like plotting.

Does anybody know some C(++) source which does this?

Many thanks for a hint,
Helmut.

Signature

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Robert Israel - 28 Jun 2009 18:16 GMT
> Hi,
>
> I have a (big) matrix computed by a C++ program.
> I'd like to write the data from within that program to a (binary) file (a
> Maple m-file)
> which can be read by Maple for further processing like plotting.

It's simplest to use text files rather than binary files.  I don't think
the .m format offers any particular advantages, and it has the disadvantage
that compatibility between different releases of Maple is not guaranteed.
Signature

Robert Israel              israel@math.MyUniversitysInitials.ca
Department of Mathematics        http://www.math.ubc.ca/~israel
University of British Columbia            Vancouver, BC, Canada

Helmut Jarausch - 29 Jun 2009 11:40 GMT
>> Hi,
>>
[quoted text clipped - 6 lines]
> the .m format offers any particular advantages, and it has the disadvantage
> that compatibility between different releases of Maple is not guaranteed.

Thanks, but since the matrix has a quarter of a million items I thought a binary
format would be smaller and faster to read/write.

Helmut.

Signature

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Axel Vogt - 29 Jun 2009 14:35 GMT
>>> Hi,
>>>
[quoted text clipped - 14 lines]
>
> Helmut.

Uncompressed that would be ~ 7 MB which is not so big for
an usual PC and I would guess most time is spent by Maple
to validate and filling by reading such a file.
Helmut Jarausch - 29 Jun 2009 15:22 GMT
>>>> Hi,
>>>>
[quoted text clipped - 19 lines]
> an usual PC and I would guess most time is spent by Maple
> to validate and filling by reading such a file.

Even worse, read-ing the file was nearly a no-op on my machine.
But plotting (even a much smaller 31x31 Matrix (instead of 511x511))
with plots[surfdata] takes a lot of time (on my PhenomII 3GHz)
And still worser the export to GIF or JPEG seems to be completely
broken since the right most 1/3 of the image is moved to the left.

This is with Maple13 (on AMD64)

Have others made similar bad experience?

Helmut.

Signature

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

Axel Vogt - 29 Jun 2009 17:29 GMT
>>>>> Hi,
>>>>>
[quoted text clipped - 31 lines]
>
> Helmut.

I forgot, whether there is a really efficient way (IIRC it is
something like 'WriteMatrix' or so ...):

Digits:=18; # to have full length for floats

  fName:="D:\\temp\\tst.txt";
  A:=Array(1 .. 511^2, 'i -> evalhf(1/i)', datatype=float[8]);

  fd := fopen(fName,WRITE,TEXT);
  st:=time():
  writedata(fd,convert(A,listlist));
  time() - st;
  fclose(fd);

needs about 8.5 sec and reading needs twice the time:

  fd := fopen(fName,READ,TEXT);
  st:=time():
  inData:=readdata(fd, 1):
  time() - st;
                                17.906

Converting to Array (Upper Case) is ~ 0.5 sec

  st:=time():
  B:=convert(inData, Array, datatype=float[8]);
  time() - st;

You also may turn off autosave (as the Maple file is large)
and may wish to delete the Arrays (mark with mouse and delete),
otherwise they are stored if the file is saved.

Using Maple13 classic on a medium sized PC with WIN XP.
Robert Israel - 29 Jun 2009 18:18 GMT
> >>>>> Hi,
> >>>>>
[quoted text clipped - 34 lines]
> I forgot, whether there is a really efficient way (IIRC it is
> something like 'WriteMatrix' or so ...):

Perhaps you're thinking of writebytes and readbytes.

fName:="D:\\temp\\tst.txt";
A:=Array(1 .. 511^2, 'i -> evalhf(1/i)', datatype=float[8]);
st:= time():
writebytes(fName, A);
time()-st;
fclose(fName);

This took 0.249 seconds on my computer in Maple 13 Classic under Windows
Vista, where your writedata example took 4.509 sec.  The resulting file
is 2041 KB, compared to 4333 KB for the writedata version.

st:= time():
B:= Array(1..511^2,datatype=float[8]);
readbytes(fName,B);
time()-st;

Takes 0.234 seconds.

> Digits:=18; # to have full length for floats
>
[quoted text clipped - 27 lines]
> Using Maple13 classic on a medium sized PC with WIN XP.
>
Signature

Robert Israel              israel@math.MyUniversitysInitials.ca
Department of Mathematics        http://www.math.ubc.ca/~israel
University of British Columbia            Vancouver, BC, Canada

Axel Vogt - 29 Jun 2009 18:41 GMT
>>>>>>> Hi,
>>>>>>>
[quoted text clipped - 50 lines]
>
> Takes 0.234 seconds.

Thanks - that's convincing :-)

>> Digits:=18; # to have full length for floats
>>
[quoted text clipped - 26 lines]
>>
>> Using Maple13 classic on a medium sized PC with WIN XP.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.