The Mathematica Journal
Departments
Feature Articles
Columns
New Products
New Publications
Classifieds
Calendar
News Bulletins
Mailbox
Letters
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Home
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.

General

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.

[Graphics:../Images/index_gr_194.gif]
[Graphics:../Images/index_gr_195.gif]
[Graphics:../Images/index_gr_196.gif]
[Graphics:../Images/index_gr_197.gif]

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.

Graphics

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.

[Graphics:../Images/index_gr_198.gif]

[Graphics:../Images/index_gr_199.gif]

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

[Graphics:../Images/index_gr_200.gif]

[Graphics:../Images/index_gr_201.gif]

[Graphics:../Images/index_gr_202.gif]

[Graphics:../Images/index_gr_203.gif]

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

[Graphics:../Images/index_gr_204.gif]

[Graphics:../Images/index_gr_205.gif]

Animation

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.

[Graphics:../Images/index_gr_206.gif]

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

[Graphics:../Images/index_gr_218.gif]

Sound

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.

[Graphics:../Images/index_gr_220.gif]

[Graphics:../Images/index_gr_221.gif]

Data

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.

[Graphics:../Images/index_gr_222.gif]
.      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.

[Graphics:../Images/index_gr_223.gif]
[Graphics:../Images/index_gr_224.gif]

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.

[Graphics:../Images/index_gr_225.gif]
[Graphics:../Images/index_gr_226.gif]

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.

[Graphics:../Images/index_gr_227.gif]
[Graphics:../Images/index_gr_228.gif]
[Graphics:../Images/index_gr_229.gif]
[Graphics:../Images/index_gr_230.gif]
[Graphics:../Images/index_gr_231.gif]

Documents

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.

[Graphics:../Images/index_gr_235.gif]
      <math>
      <msup>
        <mrow>
          <mo>(</mo>
          <mrow>
            <mi>x</mi>
            <mo>+</mo>
            <mi>y</mi>
          </mrow>
          <mo>)</mo>
        </mrow>
        <mn>2</mn>
      </msup>
      </math>
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.

[Graphics:../Images/index_gr_237.gif]
[Graphics:../Images/index_gr_238.gif]

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]