This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Nand (4.1)Export

Import

FilledSmallSquareImport["file.ext"] imports data from a file, assuming that it is in the format indicated by the file extension ext, and converts it to a Mathematica expression.

FilledSmallSquareImport["file", "format"] imports data in the specified format from a file.

FilledSmallSquareImport attempts to give a Mathematica expression whose meaning is as close as possible to the data in the external file.

FilledSmallSquareImport can handle textual and tabular data, as well as graphics and sounds.

FilledSmallSquare The following basic formats are supported for textual and tabular data:

FilledSmallSquare"Text" and "UnicodeText" return single Mathematica strings.

FilledSmallSquare"Lines" and "Words" return lists of Mathematica strings.

FilledSmallSquare"List" returns a list of Mathematica numbers or strings.

FilledSmallSquare"Table" and "CSV" return a list of lists of Mathematica numbers or strings.

FilledSmallSquare In "List" "Table", and CSV format, numbers can be read in C or Fortran-like "E" notation.

FilledSmallSquare Numbers without explicit decimal points are returned as exact integers.

FilledSmallSquare In "Table" format, columns can be separated by spaces or tabs.

FilledSmallSquare In "Words" format, words can be separated by any form of white space.

FilledSmallSquare In "CSV" format, columns are separated by commas.

FilledSmallSquareImport["file.txt"] uses "Text" format.

FilledSmallSquareImport["file.dat"] uses "Table" format.

FilledSmallSquareImport["file.csv"] uses "CSV" format.

FilledSmallSquare The following additional formats are also supported for numerical data:

FilledSmallSquare Two-dimensional graphics formats are imported as Graphics objects; sound formats are imported as Sound objects.

FilledSmallSquare Animated graphics are imported as lists of Graphics objects.

FilledSmallSquare The following formats yield expressions of the form Graphics[data, opts]:

FilledSmallSquare The following formats yield expressions of the form Graphics[Raster[data], opts]:

FilledSmallSquare Imported raster data normally consists of integers; ColorFunction is often used to specify a color map.

FilledSmallSquare The following formats return objects of the form Graphics3D[data, opts]:

FilledSmallSquare The following formats yield expressions of the form Sound[SampledSoundList[data, r]]:

FilledSmallSquare The following XML document formats are supported:

FilledSmallSquare If "MathML", "NotebookML", or "ExpressionML" is specified as the import format, and the document is not of the specified format, Import will return $Failed.

FilledSmallSquare If "XML" is specified as the format, Import will recognize MathML, NotebookML, and ExpressionML documents and interpret such data accordingly. Data in other XML formats will be imported as a symbolic XML expression.

FilledSmallSquare If "SymbolicXML" is specified as the format, Import converts any XML file to symbolic XML, regardless of what its document type is.

FilledSmallSquare For "MathML" format, Import interprets presentation elements as expressions according to TraditionalForm interpretation rules, if possible. If the MathML data does not correspond to an expression in TraditionalForm syntax, Import returns a box expression.

FilledSmallSquare The "NB" format may be used with Import to obtain a notebook expression from a Mathematica notebook file:

FilledSmallSquare The following general options can be given:

FilledSmallSquare Possible formats accepted by Import are given in the list $ImportFormats.

FilledSmallSquareImport["!prog", "format"] imports data from a pipe.

FilledSmallSquare See The Mathematica Book: Section 1.11.3, Section 2.9.20 and Section 2.11.7.

FilledSmallSquare See also: Export, ImportString, $ImportFormats, ReadList.

Additional Information

Many Import formats have private options that are specified using the option ConversionOptions: Import["file", "format", ConversionOptions -> opts].

BMP

Import supports Windows device-independent bitmaps that are compressed using run-length encoding.

CSV

The following options can be given:

FilledSmallSquare Setting "Numeric" to False stores numbers as their string textual representations.

ExpressionML

The following option can be given:

FilledSmallSquare See also the options listed for "SymbolicXML".

FITS

The following option can be given:

FilledSmallSquare The option "Verbose" determines whether header information is imported. It also determines the format of the imported data.

FilledSmallSquare With "Verbose" False, header information is not imported.

FilledSmallSquare With "Verbose" False, data is formatted as a list of matrices, even if the data comes from multiple Header Data Units (HDUs). This allows for easy plotting by mapping the data with functions like ListDensityPlot and ListContourPlot.

FilledSmallSquare With "Verbose" True, import returns a list of HDUs. Each HDU is a list containing a header and a data unit.

FilledSmallSquare With "Verbose" True, each header is a list of entries of the form _String "Value" _, "Comment" _String This allows programmatic access to values and comments in the headers.

FilledSmallSquare The value of a header entry named ent can be extracted from a header named head with the following: "Value"/.(ent/.head) The comment can be extracted with "Comment"/.(ent/.head)

FilledSmallSquare With "Verbose" True, data is not returned as a list of matrices, but as tensors paired in lists with their headers. A 0-dimensional tensor is represented by Null.

FilledSmallSquare The primary HDU and IMAGE extensions are imported as integer or real data.

FilledSmallSquare ASCII table extensions are imported as string data.

FilledSmallSquare Other extensions are not supported.

GIF

The following options can be given:

FilledSmallSquare The option "ColormapOutput" determines whether a GIF is imported as a Raster graphics primitive with a color map ColorFunction and a matrix of indices into the color map, or whether the imported Raster graphics primitive contains a normal matrix of sample values. A grayscale image will import without the use of a color map ColorFunction.

FilledSmallSquare If the GIF is an animated GIF with multiple frames, "ImageIndex" -> i will select a particular frame to import. "ImageIndex" -> , , ... will select a list of frames from the animated GIF. By default, all frames of an animated GIF are imported.

HDF

The following option can be given:

FilledSmallSquare HDF files can contain multiple datasets in a single file. By default, the first dataset in an HDF file is imported. "DatasetSelection" -> i will attempt to import the dataset at index i. "DatasetSelection" -> string will attempt to find a dataset named with label string. "DatasetSelection" -> Information will not import the datasets in the file but will instead return a list of length equal to the number of datasets in the file and contain information about the format types, names, and dimensions of the datasets.

FilledSmallSquare Import of HDF currently only supports the "scientific datasets" SDS interface.

JPEG

The following options can be given:

FilledSmallSquare Although the JPEG format is not stored as a color-mapped image, Import can color reduce or quantize the JPEG as it is being imported. By default, no color reduction is done.

FilledSmallSquare Using a "ColorReductionDither" method can provide better resulting images once a color map is chosen by dithering the resulting image. "ColorReductionDither" -> "Ordered" provides relatively fast and medium quality dithering, while "ColorReductionDither" -> "Floyd-Steinberg" provides the best quality error-diffusion dithering, requiring more time and memory. "ColorReductionDither" -> None will perform no dithering on the imported image.

FilledSmallSquare"ColorReduction" -> "Fixed" chooses evenly spaced colors from a color space, which may not pick the most optimal colors for the image. "ColorReduction" -> "Adaptive" uses a median-cut algorithm to choose the optimal set of colors for an image.

FilledSmallSquare"ColorReductionPalette" -> Automatic will choose an adaptive set of at most 256 colors. "ColorReductionPalette" -> n will choose at most n colors for the color palette. "ColorReductionPalette" -> , , ... specifies a list of color directives to use to color reduce the image. The values for must be CMYKColor, GrayLevel, Hue, or RGBColor directives. The number of colors chosen for "ColorReductionPalette" must be between 2 and 256.

FilledSmallSquare The following example produces an image using a color map of "browser safe" 216 colors: Import["file.jpg", "JPEG", ConversionOptions -> {"ColorReduction" -> "Fixed", "ColorReductionPalette" -> 216}].

FilledSmallSquare Color reduction of JPEG images only applies to JPEG images with three color components. If you are producing these JPEG images yourself, you can force the use of three color components with Export and "Colorspace" -> "RGBColor": Export["file.jpg", gr, "JPEG", ConversionOptions->{"Colorspace" -> RGBColor}].

FilledSmallSquare The option "Colorspace" can be explicitly set to RGBColor or GrayLevel to force the resulting imported image to a specific color space.

List

The following options can be given:

FilledSmallSquare The option "DateStyle" can be set to the values "American", "European", or "Scientific".

MathML

The following option can be given:

FilledSmallSquare See also the options listed for "SymbolicXML".

NotebookML

The following option can be given:

FilledSmallSquare See also the options listed for "SymbolicXML".

PBM, PGM, PPM, PNM

The following options can be given:

FilledSmallSquare"CheckDepth" -> True will check the data on importing to see if the actual data stored in the image could be represented by a reduced color space. For example, if a PPM file contains identical red, green, and blue components for all pixels, a Raster of graylevels is imported.

FilledSmallSquare Although the PBM formats are not stored as a color-mapped image, Import can color reduce or quantize the PBM as it is being imported. By default, no color reduction is done. "ColorReduction" -> True will perform color quantization.

FilledSmallSquare By dithering the resulting image, "ColorReductionDither" -> True will provide better resulting images once a color map is chosen.

FilledSmallSquare"ColorReductionPalette" -> Automatic will choose an adaptive set of at most 256 colors. "ColorReductionPalette" -> n will choose at most n colors for the color palette. "ColorReductionPalette" -> , , ... specifies a list of color directives to use to color reduce the image. The values for must be CMYKColor, GrayLevel, Hue, or RGBColor directives. The number of colors chosen for "ColorReductionPalette" must be between 2 and 256.

SDTS

The following options can be given:

FilledSmallSquare The option "FillValue" is used when importing nonrectangular data. Since every dataset is rectangular, there will be data points that do not correspond to any physical data. "FillValue" specifies what integer value is used in Mathematica to represent these data points. Adjusting the "FillValue" can improve the contrast with other data points when plotting the data.

FilledSmallSquare The option "ElementSkip" n is an optimization which specifies to only import every th row and column of the dataset. This reduces the timing for Import and other functions acting on the imported data. This is useful when the dataset has a greater resolution than required.

FilledSmallSquare Only import of Digital Elevation Models (DEM) are supported. Most DEM data in SDTS format come in gzipped tar archives. The DEM data is contained in a single file in the archive, named ????CEL0.DDF.

SymbolicXML

The following options can be given:

Table

The following options can be given:

FilledSmallSquare The option "DateStyle" can be set to the values "American", "European", or "Scientific".

FilledSmallSquare A field is considered to be a date if it consists of three adjacent, forward slash-delimited integers of which the month, day, and year values appear to be reasonable. Months must be between 1 and 12 inclusive. The day must not lie outside the valid range of days for the given month. A year's validity can be determined indirectly by "TwoDigitYearFunction".

FilledSmallSquare A date field will be broken into a list of the form year, month, day.

FilledSmallSquare The option "TwoDigitYearFunction" can be set to None, Automatic, or an arbitrary function.

FilledSmallSquare Setting the "TwoDigitYearFunction" to its default value of None keeps the date field from being interpreted as a date if the year has only two-digits.

FilledSmallSquare When "TwoDigitYearFunction" is set to Automatic, 1900 is added to the year and the field is interpreted as a date.

FilledSmallSquare User-defined functions for "TwoDigitYearFunction" must return Integer values.

FilledSmallSquare Setting "DataBlockLength" -> n specifies that the file's contents are arranged in a structure that repeats every n rows. Adjusting this option to fit your data set will increase the speed at which the file is read and interpreted.

FilledSmallSquare Specifying "DataBlockErrorChecking" -> True forces Import to verify that the data block frequency in "DataBlockLength" matches the actual contents of the file. If the frequency does not match, Import will use more conservative, but slower, heuristics to deduce the types of fields. Setting "DataBlockErrorChecking" -> False bypasses this checking to reach completion more quickly; however, the data may be interpreted incorrectly.

TIFF

The following options can be given:

FilledSmallSquare"CheckDepth" -> True will check the data on importing to see if the actual bit depth of the TIFF is smaller than one byte per image sample, and this can result in a Raster with integer values scaled to a more exact representation of what was stored in the TIFF. For example, a 4-bit TIFF image would be imported as a Raster with a matrix of integer values between 0 and 15 and not the normal 0 to 255 associated with a byte of image sample information.

FilledSmallSquare If the TIFF contains multiple images, "ImageIndex" -> i will select a particular image to import. "ImageIndex" -> , , ... will select a list of images from the TIFF. By default, all images of a TIFF are imported.

XML

See the options listed for "SymbolicXML".

Nand (4.1)Export