University of Tennessee
Mathematics Department

Maple FAQ

[Note: This page is most helpful if you use your browser's Find command and search for Keywords.]

   Save:
There are three different types of Maple file formats that you may save your work in: Maple language files (or plain-text), internal format files (maple code, still ASCII so you can email it), and for graphical user interface, worksheet files (ASCII as well). Since all of these files are ASCII you may open a file in Linux that was saved in Windows and vice versa.

Most people will only be concerned with the worksheet files as this is what happens when you go to File:Save As.. in the graphical user interface. The suffix for these files is .mws (older versions of Maple used .ms, but these can be viewed with the newer releases). This file format will save everything that you see on your screen, including plots (therefore, they tend to be very large files).

The Maple language file is the simplest filetype to understand. It saves only objects and procedures assigned to variables, and it saves them in a plain-text file. It simply saves the commands used to declare the variables, so you can read and edit the file afterwards (this is an alternative method of scripting a session). You can also create a Maple language file yourself since it is just a plain-text file with Maple commands.

In this example, we will declare two variables by assigning them values, and then save the two variables to a text file:

> a:=1;

a := 1

> b:=2;

b := 2

> save b,a,"test.txt";

We can view this text file using any text editor in Windows or Linux, or using the Linux/Unix command more:

UNIX> more test.txt
b := 2;
a := 1;

The same may be accomplished in Xmaple by going to File:Save As.. and choosing the Maple Text file format. This will save all declared variables, whereas with the command line you can specify certain variables to save. Also, you can specify the order with the command line, which might be useful on occassion.

The internal format filetype, denoted by a .m suffix, is very similar to the worksheet filetype in appearence. This filetype saves objects and procedures in maple's native language, and thus can be loaded very quickly. The language is also very compact, so the file sizes tend to be small. This format does not save the entire worksheet, however, only objects assigned to variables. In many ways it is the compromise between the two previous filetypes. Similarly, therefore, it shares some disadvantages from both of the previous filetypes. Namely, you cannot save plots like the .mws files, and you cannot edit the .m files like you can the .txt files. In general this is the least useful filetype for the everyday user. The following example shows how to save the previous expressions to an internal format filetype, (be sure to specify which variables to save or else Maple will save all pre-defined variables as well!):

> a:=1;

a := 1

> b:=2;

b := 2

> save b,a,"test.m";

We can view this text file using any text editor in Windows or Linux, or using the Linux/Unix command more:

UNIX> more test.m
MVR5
I"b""#6",
I"a"""F$

[Keywords: save, load, read, open, file, filetype, worksheet, script, diary]

   Read/Open:
To open a Maple worksheet (.mws file) in Xmaple, go to File:Open and select the appropriate file.

To open a simple text document (for word-processing only), you may go to File:Open, choose Filetype MapleText, select the .txt file, then choose text to open a text window. You may copy and paste to and from this text document.

In order to read in variables from either a internal format file or Maple language file (see the save section for descriptions of these filetypes), use the read command as follows:

> read "test.m";

or,

> read "test.txt";

The read command reads and executes the commands in the order they appear. In order to force Maple to show what commands it is executing as it reads in a .txt file (convenient for printing out), you must first type interface(echo=4);. This will turn on echo regardless of whether input is from the keyboard or a seperate file (later you may set it back to echo=1). Maple will always display the output of a command from a .txt file unless the output is surpressed by a ":". With a .m file, all the variables will be assigned, although nothing will be displayed. You have to ask Maple to eval the variables to show the values. This is another of the disadvantages of using the .m file format.

To read in data from a text file which contains integers or floats in columns seperated by white space, use the readdata command. You may read each of n columns as integer, float, or even string. The syntax is: readdata("filename.txt",format,n);. For example:

> data1:= readdata("data1.txt",float,5):

data1:= [[2.36, 1.43, .83, 1.33, 3.68], [2.06, 1.43, .62, 1.33, 3.68],      
[2.36, 1.49, 1.08, 1.54, 6.78], [2.36, 1.49, .97, 1.54, 6.78],
[2.49, 1.52, 1.04, 1.86, 5.22], [2.77, 1.82, 1.19, 3.06, 5.06],
[2.47, 1.82, .99, 3.06, 5.06], [2.66, 1.42, 1.4, 3.23, 5.86],
[3.37, 2.06, 2.18, 3.88, 5.11], [3.22, 2.04, 1.91, 4.08, 6.8],

> data2:= readdata("data2.txt",[integer,float]):

data2:= [[1, 3.68],       
[2, 3.68],
[3, 6.78],
[4, 6.78],
[5, 5.22]]

In these examples, there are 5 columns of floats in data1.txt and 2 columns in data2.txt, integers vs. floats. These variables are now lists of lists which can be used in statplot or in any calculations. You may also use the convert command to change the list of lists into sets or matrices (e.g. matrix1:= convert(data1,matrix);). For more complicated input files, see the help on fscanf, readline, or stats[importdata].

[Keywords: read, load, open, readdata, importdata, import, convert, fscanf, fopen, data, input, readline]

   Printing:
To print a maple worksheet from the Mathlab (in Xmaple only) click the print icon. In Linux/Unix select the Print Command option and type in lpr -PA322. In Windows 95/NT, choose "Math Lab Printer".

Since newer versions of Maple place plots inline, or embedded in the worksheet, you generally have to print the entire worksheet to print out plots. Also, although you can adjust the size of the plots in the worksheet by clicking the plot and resizing it, you cannot necessarily get a full page printout this way. However, if you need to print each plot on a seperate full page, you can change the maple plotdevice to print to a seperate window: interface(plotdevice=window);. Then you can click the print icon to print only this window. (Use interface(plotdevice=default); to change back.) You could also go to Options -> Plot Display -> Window which does the same thing.

Other plotdevice options include: gif, jpeg, postscript, and char (a la `text-maple'), however you have to specify a plotoutput file with these formats. You could also print plots and worksheets to postscript files through the print icon by selecting the Output to File: option. For more information, and many more options, see ?plot[options].

In order to insert a page break, go to Format -> Paragraph.. and check the box marked "Start New Page". The line at which the cursor is on when this is clicked will begin a new page. Highlighting a selection to be on a new page will not work, as this will simply put each line in the selection as the first line of a new page. Always preview the document before printing out when using the New Page command, as it does not always work like you want it to (especially with Sections and Subsections).

[Keywords: print, lpr, plot, plot[options], inline, window, plotdevice, interface, page breaks, gif, jpeg, postscript, ps, ghostview, resize, full page, plot display]

  Return to UTK Math Department WWW Server

Last updated: Mon Nov 2 13:02:01 EST 1998