The Mathematica Journal
Feature Articles
New Products
New Publications
News Bulletins
Write Us
About the Journal
Staff and Contributors
Back Issues
Download this Issue

Import and Export

A very visible change to the core system is the support for import and export of a number of file formats which should make it easy to interface with a wide variety of other systems. Currently some 25 different formats are supported, covering such areas as raster graphics, vector graphics, animation, sound, numeric data, textual data, and document formats, as well as binary data.


The general framework is to use only two functions: Import and Export. Formats can either be derived from file extensions or specified explicitly. This is the current list of formats.


For most of these formats there is additional information available under Additional Information in the Reference Guide for Export and Import. For instance many of these formats have additional options that control their use, such as picking a browser-safe color map when saving a GIF file, and these are documented in the Reference Guide entry above.


This first example is the original data for the cat used in the Tour of Mathematica. And judging from questions coming into Wolfram Research, many users wanted to perform the manipulations shown there.



Below are some other common raster graphics formats, TIFF and JPEG.





Below is an example of a resolution independent (or vector) graphics representation, in this case PostScript.




Another useful pedagogical tool is to be able to work with animations. Right now, animated GIFs are what works well with the web, and you can import and export these in Mathematica 4.

This is a simple illustration of the convergence of a Fourier series.


This can be exported using various options to control its appearance such as whether it loops and the delay between images.



There are also a number of (sampled) sound file formats. The formats supported include; AIFF, AU (or [Graphics:../Images/index_gr_219.gif] law encoding), SND and WAV.




Mathematica 4 supports two common numeric data file formats: MAT (numeric matrices) and HDF (hierarchical data format). We saw an example of the MAT format previously.

Another common way of getting data is as some form of textual file.

.      Semi-Major   Orbit  Equator   Rotate
.       Distance    Period  Radius   Period
Object  (1000km)    (days)    (km)   (days)
-------  -------   --------  -----  -------
Mercury    57910     87.969   2439    58.65
Venus     108200    224.701   6052  -243.16
Earth     149600    365.256   6378     0.99
Mars      227940    686.980   3397     1.03
Ceres     413400   1681.25     470     0.38
Jupiter   778330   4332.59   71492     0.41
Saturn   1429400  10759.20   60268     0.45
Uranus   2870990  30684.9    25559    -0.72
Neptune  4504300  60190.3    24764     0.67
Pluto    5913520  90465.      1160    -6.39

There are two formats, "Table" and "List", which attempt to interpret numbers in the text file whenever possible. The main difference is that "Table" attempts to find a two-dimensional array in the data, whereas "List" attempts to read it as a one-dimensional array.


One can also read data as a pure textual file. The formats: "UnicodeText", "Text", "Lines", and "Words" do this. The main difference is how they try to break up the data into discrete pieces. Additional processing can then be done on the resulting strings.


Another common case is to have a binary data file format. In Version 4 there are two Experimental` context functions (BinaryImport and BinaryExport) that simplify the task of importing and exporting general binary files. Below the string is exported as a sequence of bytes.



The main document formats into which notebooks can be converted are [Graphics:../Images/index_gr_232.gif] and HTML, both of which have been greatly enhanced in Version 4. These formats are designed to preserve much of the look and feel of the original notebook document, but there are, of course, obvious limits to what can be achieved for these formats in that regard. In both cases these conversions are extensible and there is additional information available on how this works in the corresponding reference guide entries.

In the case of [Graphics:../Images/index_gr_233.gif] there is now a version of the Mathematica fonts that fits with modern [Graphics:../Images/index_gr_234.gif] distributions and allows these documents to preserve much of the look and feel of a typical notebook document.

Below is an example where HTML + MathML is being exported instead of the usual HTML + GIF. The portion containing the MathML markup has been extracted from resulting string.

Copy and paste this piece of MathML into Mathematica 4. You will see that the expression is automatically converted into a formula in TraditionalForm. This is a preview of what the web will likely eventually be, where a formula is more then a graphic image, and you can actually manipulate and compute with it, as you can right now in Mathematica.

Compare this output to the box representation used by Mathematica. Apart from additional markup in MathML such as <mi> for math italic variables and <mo> for math operators these expressions are structurally identical.


This is, of course, no accident, since Wolfram Research has been closely involved in the MathML design from the very start. And in addition we are hosting a conference on MathML in the fall of 2000.

Converted by Mathematica      June 4, 2000

[Article Index] [Prev Page][Next Page]