•Import und Export  

Die neuen Import Formate sind  ExpressionML, FITS, MathML, NB, NotebookML, SDTS, SymbolicXML, XML.

Die neuen Export Formate sind ExpressionML, FITS, MathML, NB, NotebookML, SVG, techexplorer, XML.

•NotebookML und ExpressionML Import/Export Format

Notebooks und Ausdrücke können mit Hilfe der neuen XML Erweiterungen im Standard XML Format abgespeichert werden. Das folgende Beispiel zeigt wie man einen Mathematica Ausdruck in ExpressionML umwandelt.

ExportString[Unevaluated[∫ _ 0^(2 π) Sin[x] d x], "ExpressionML"]

<?xml version='1.0'?>\n<!DOCTYPE Expression SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>\n<Expression xmlns:mathematica='http://www.wolfram.com/XML/'\n    xmlns='http://www.wolfram.com/XML/'>\n <Function>\n  <Symbol>Integrate</Symbol>\n  <Function>\n   <Symbol>Sin</Symbol>\n   <Symbol>x</Symbol>\n  </Function>\n  <Function>\n   <Symbol>List</Symbol>\n   <Symbol>x</Symbol>\n   <Number>0</Number>\n   <Function>\n    <Symbol>Times</Symbol>\n    <Number>2</Number>\n    <Symbol>Pi</Symbol>\n   </Function>\n  </Function>\n </Function>\n</Expression>

nb = Notebook[{Cell["test", "Title"], Cell["x^2", "Input"]}] ; ExportString[nb, "NotebookML"]

<?xml version='1.0'?>\n<!DOCTYPE Notebook SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>\n<Notebook CreatedBy='Mathematica 4.2'\n    xmlns:xhtml='http://www.w3.org/1999/xhtml'\n    xmlns:mathematica='http://www.wolfram.com/XML/'\n    xmlns='http://www.wolfram.com/XML/'>\n <List>\n  <Cell class='Title'>\n   <String>test</String>\n   <Style>\n    <String>Title</String>\n   </Style>\n  </Cell>\n  <Cell class='Input'>\n   <String>x^2</String>\n   <Style>\n    <String>Input</String>\n   </Style>\n  </Cell>\n </List>\n</Notebook>

•FITS Data Import/Export Format

Mathematica 4.2 unterstützt das Flexible Image Transport System (FITS) Format, ein logisches Datenformat entwickelt von Astronomen für den Austausch astronischer Daten. Der Standard wird von der International Astronomical Union kontrolliert. Das FITS Format wird bei der NASA als Standarddatenformat benutzt.

Die Option ConversionOptions kann benutzt werden um Header-Informationen mit zu importieren.

Beispieldateien im FITS Format sind auf http://www.cv.nrao.edu/fits/data/tests/incunabula/mssso82/ zu finden.

Mit Hilfe des J/Link GetURL Beispielprogramms kann eine beliebige Binärdatei vom Internet auf die Festplatte geladen werden.

Needs["JLink`"]
$ProxyHost=None;
$ProxyPort=8080;

Options[GetURL]={ProxyHost :> $ProxyHost,
      ProxyPort :> $ProxyPort};
GetURL[url_String, opts___?OptionQ] :=
    JavaBlock[
        Module[{u, stream, numRead, outFile, buf, prxyHost, prxyPort},
            {prxyHost, prxyPort} = {ProxyHost, ProxyPort} /. Flatten[{opts}] /. Options[GetURL];
            StartJava[];
            If[StringQ[prxyHost],
                (* Set properties to force use of proxy. *)
                SetInternetProxy[prxyHost, prxyPort]
            ];
            u = JavaNew["java.net.URL", url];
            (* This is where the error will show up if the URL is not valid.
               A Java exception will be thrown during openStream, which
               causes the method to return $Failed.
            *)
            stream = u@openStream[];
            If[stream === $Failed, Return[$Failed]];
            buf = JavaNew["[B", 5000]; (* 5000 is an arbitrary buffer size *)
            outFile = OpenTemporary[DOSTextFormat->False];
            While[(numRead = stream@read[buf]) > 0,
                WriteString[outFile, FromCharacterCode[If[# < 0, # + 256, #]& /@ Take[Val[buf], numRead]]]
            ];
            stream@close[];
            Close[outFile]   (* Close returns the filename *)
        ]
    ]

Mit Hilfe des J/Link GetURL Beispielprogramms  http://www.cv.nrao.edu/fits/data/tests/incunabula/mssso82/sharp1.fits˙˙

tempfile = GetURL["http://www.cv.nrao.edu/fits/data/tests/incunabula/mssso82/sharp1.fits"] ;

mypic = Import[tempfile, "FITS", ConversionOptions -> {"Verbose" -> True}] ; DeleteFile[tempfile] ;

mypic[[1, 1]]

{SIMPLE -> {Value -> True, Comment -> }, BITPIX -> {Value -> 16.`, Comment -> }, NAXIS -> {Value -> 3.`, Comment -> }, NAXIS1 -> {Value -> 196.`, Comment -> }, NAXIS2 -> {Value -> 248.`, Comment -> }, NAXIS3 -> {Value -> 1.`, Comment -> }, ORIGIN -> {Value -> 'MSSSO   ', Comment -> }, COMMENT -> =     SADFILE:- US41A                                                   , BSCALE -> {Value -> 1.`, Comment -> }, BZERO -> {Value -> 0.`, Comment -> }, COMMENT -> =  SADFILE:- IGI                                                        , OBJECT -> {Value -> 'ARP 140 ', Comment -> }, CDELT2 -> {Value -> 0.00014125`, Comment -> }, CRPIX1 -> {Value -> 151.2`, Comment -> }, CRPIX2 -> {Value -> 116.`, Comment -> }, CRVAL1 -> {Value -> 12.125`, Comment -> }, CRVAL2 -> {Value -> -7.328`, Comment -> }, COMMENT -> =  H ALPHA IMAGE                                                        , CDELT1 -> {Value -> -0.00014125`, Comment -> }, END -> {Value -> 0.`}}

mypic[[1, 2]] // Dimensions

{1, 248, 196}

mypic[[1, 2, 1]] // Dimensions

{248, 196}

Die Daten können mittels ListDensityPlot geplottet werden.

ListDensityPlot[mypic[[1, 2, 1]], Mesh -> False, Frame -> False, PlotRange -> {{1, 248}, {1, 196}, Automatic}] ;

[Graphics:../HTMLFiles/index_166.gif]

•SDTS Data Import Format

The SDTS format was designed by the US government for transfer of spatial data such as Digital Elevation Maps (DEMs) and satellite images.  Each data archive contains a set of files.  The specific file corresponding to the elevation data can be imported for analysis.

Der "Spatial Data Transfer Standard" (SDTS) ist ein Übertragungsstandard für räumliche Daten.

Der SDTS Datensatz 1031CEL0.DDF ist in ftp://sdts.er.usgs.gov/pub/sdts/datasets/raster/dem/dem_oct_2001/1031743.dem.sdts.tar.gz enthalten und als 1031CEL0.DDF.gz kopiert auf http://www.mertig.com/data/ .
Das Datenfile kann wiederum mittels einer kleinen JLink-Hilfsfunktion direct aus dem Internet in einen Mathematica String geladen werden.

Needs["JLink`"] ; Off[General :: spell] ; Off[General :: spell1] ;

GZIPURLAsString[url_String] := JavaBlock[Module[{u, stream, numRead, outFile, buf, s}, InstallJava[] ;  u = JavaNew["java.net.URL", url] ;  stream = u @ openStream[] ;  stream = JavaNew["java.util.zip.GZIPInputStream", stream] ;  If[stream === $Failed, Return[$Failed]] ;  buf = JavaNew["[B", 50000] ;  s = "" ;  While[(numRead = stream @ read[buf]) > 0, s = (s <> FromCharacterCode[(If[# < 0, # + 256, #] &) /@ Take[Val[buf], numRead]])] ;  stream @ close[] ;  s]]

sdtsasstring = GZIPURLAsString["http://www.mertig.com/data/1031CEL0.DDF.gz"] ;

DigitalElevationPlot[s_ (String | Stream)] := Module[ {heights},  heights = Import[s, "SDTS"] ;  ListPlot3D[ heights,  Mesh -> False,  ColorFunction -> (Which[# > .65, RGBColor[#, #, #], # > .3, RGBColor[0, #, 0], True, RGBColor[0, 0, #]] &),  Axes -> False,  ViewPoint -> {2.655, 1.204, 1.718},  BoxRatios -> {1, 1, .2},  ImageSize -> 600 ] ; ]

data = Import[StringToStream[sdtsasstring], "SDTS"] ;

data // Dimensions

{1409, 1016}

ListPlot3D[data, Mesh -> False, ColorFunction -> (Which[#1 > .65, RGBColor[#1, #1, #1], #1 > .3, RGBColor[0, #1, 0], True, RGBColor[0, 0, #1]] &), Axes -> False, ViewPoint -> {2.655, 1.204, 1.718}, BoxRatios -> {1, 1, .2}, ImageSize -> 500] ;

[Graphics:../HTMLFiles/index_175.gif]

InterpolatingColorMap[c_] := Function[x, (n = Length[c] - 1 ;  low = Floor[x n] ;  If[low == n, low = n - 1,] ;  high = low + 1 ;  y = x n - low ;  Hue[Mod[c[[low + 1, 1]] + y (c[[low + 2, 1]] - c[[low + 1, 1]]), 1], c[[low + 1, 2]] + y (c[[low + 2, 2]] - c[[low + 1, 2]]), c[[low + 1, 3]] + y (c[[low + 2, 3]] - c[[low + 1, 3]])])] ;

BlueGreenOrange = InterpolatingColorMap[{{0.6, 0.7, 0.7}, {0.3, 0.6, 1}, {0.1, 0.5, 1}}] ;

ListContourPlot[data, Contours -> 20, ColorFunction -> BlueGreenOrange] ; <br />

[Graphics:../HTMLFiles/index_179.gif]

•SVG Export

{MemberQ[$ExportFormats, "SVG"], MemberQ[$ImportFormats, "SVG"]}

{True, False}

Scalable Vector Graphics (SVG) ist ein auf XML basierendes Format für 2-dimensionale Graphiken.

Export["test.svg", Plot[Sin[x], {x, -6, 6}]] ;

[Graphics:../HTMLFiles/index_183.gif]

So sehen die ersten 15 Zeilen der abgespeicherten SVG Datei aus:

TableForm @ Take[Import["test.svg", "Lines"], 15]

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns='http://www.w3.org/2000/svg'
    width='288.0pt'
    height='177.994pt'
    viewBox='-6.96316 -4.30346 13.9263 8.60694'
    preserveAspectRatio='xMidYMid meet'>
<g transform='scale(1, -1) translate(0,-8.95434E-6)'
     style='fill:black; font-family:&apos;Courier New&apos;, Courier, Symbol, monospace; font-size:0.290132pt; stroke:black; stroke-width:0.0120888pt'>
  <polyline fill='none'
      points='
-6.0,1.03614 -5.76302,1.84307 -5.5132,2.5814 -5.25982,3.16632 -5.11614,3.41006
-5.05196,3.49648 -4.98229,3.57398 -4.91353,3.63346 -4.88332,3.65418 -4.85005,3.67315
-4.81872,3.68728 -4.78937,3.69725 -4.77319,3.70138 -4.75838,3.70431 -4.75021,3.70558
-4.74129,3.70668 -4.72504,3.70793 -4.70917,3.70821 -4.69423,3.70762 -4.68081,3.70638

Converted by Mathematica  (June 25, 2002)