Rechnernutzung in der Physik

Vorlesung: Rechnernutzung in der Physik Python Günter Quast Fakultät für Physik Institut für Experimentelle Kernphysik KIT – Universität des Landes...
Author: Elisabeth Haupt
22 downloads 0 Views 2MB Size
Vorlesung:

Rechnernutzung in der Physik Python

Günter Quast Fakultät für Physik Institut für Experimentelle Kernphysik

KIT – Universität des Landes Baden-Württemberg und nationales Forschungszentrum in der Helmholtz-Gemeinschaft

WS 2016/17

www.kit.edu

PYTHON & friends Literatur: python für Anfänger:

(= numpy, scipy, matplotlib) www.python-kurs.eu

offizielles python Tutorial: http://docs.python.org/2/tutorial/ numpy tutorial: http://wiki.scipy.org/Tentative_NumPy_Tutorial numpy reference manual http://docs.scipy.org/doc/numpy/reference/index.html matplotlib tutorial: http://matplotlib.org/users/pyplot_tutorial.html advanced – for future python programmers: http://www.diveintopython.net/ ipython shell, an advanced interactive shell http://ipython.org/ipython-doc/stable/interactive/tutorial.html

python appetizer

http://docs.python.org/2/tutorial/

Die Python-Shell: ein interaktiver Taschenrechner Aufruf durch Befehl

python

auf der Kommando-Zeile

Beispiel

← multiple Zuweisung

← Kontrollstrukturen Trotz seiner Einfachheit ist python eine vollwertige Programmiersprache

Python interaktiv: weitere Beispiele

← Definition einer Funktion Achtung: Einrückungen zwingend vorgeschrieben

← verschiedene Datenformate !!!

← Typumwandlung nach float geht nicht, weil Unsinn ! ( abs(a) würde gehen - ausprobieren!)

noch mehr Beispiele Funktion für Fibonacci-Zahlen ← Parameter mit Vorgabewerten und Namen

for-Schleife ← klassische Schleife über Index ← Iteration über Liste

und noch ein Beispiel mehr zu Listen ← Erzeugen & Ausgabe e. Liste ← eine von vielen Funktionen für Listen

← komfortable Initialisierung ← Bereich aus Liste ← Filtern mit logischer Funktion

← Funktion auf alle Listenelemente

letztes Beispiel

dictionaries dictionary = key-value-Paare

python Scripte Alles, was wir bisher gesehen haben, lässt sich auch in Form einer Text-Datei als Python Script ausführen: > python Fibonacci.py Datei Fibonacci.py #! /usr/bin/env python #-- Fibonacci numbers as python script ------def Fibo(min=1, max=1000): a,b=0,1 while b=min: print b, a,b=b,a+b print '*==* Demo Script: Fibonacci numbers' print '\n calling Fibo(max=10000)' Fibo(max=10000) print '\n calling Fibo(10000,1000000)' Fibo(10000,1000000)

erlaubt Ausführung direkt aus der Linux-Shell Achtung: Datei muss ausführbar sein: > chmod a+x Fibonacci.py

Ausführung: > ./Fibonacci.py

Python-Script (= Python-Programm) erlaubt: - Dokumentation - Weiterentwicklung/Modifikation - Wiederverwendung - Weitergabe von Code

NumPy für Vektoren und Matrizen

NumPy's NumPy'smain mainobject objectisisthe thehomogeneous homogeneousmultidimensional multidimensionalarray. array. ItItisisaatable tableof ofelements elements(usually (usuallynumbers), numbers),all allof ofthe thesame sametype, type, indexed indexed by byaatuple tupleof ofpositive positiveintegers. integers.In InNumpy Numpydimensions dimensionsare are called number Empfehlung: calledaxes. axes.The The numberof ofaxes axesisisrank. rank. http://www.python-kurs.eu/numpy.php

NumPy NumPy ist ein fundamentales Paket zum wissenschaftlichen Rechnen in Python – zentrales Datenobjekt ist ndarray zur Handhabung von Vektoren und Matrizen aus homogenen Datentypen (im Gegensatz zu Listen!) – viele trigonometrische, hyperbolische und andere spezielle Funktionen sind implementiert – Rechenoperationen wirken auf ganze arrays, hohe Verarbeitungsgeschwindigkeit durch compilierten Code

Beispiel:

>>> import numpy as np ← Einbinden von numpy als alias „np“ >>> a=np.array([1,2,3,4],'f') >>> a array([ 1.,

2.,

3.,

4.], dtype=float32)

>>> b=np.array([0.5,1.,1.5,2.]) >>> b array([ 0.5, >>> b-a

1. ,

1.5,

2. ]) ← element-weise Subtraktion

array([-0.5, -1. , -1.5, -2. ]) >>>

numpy array numpy.array( object,

„array-like“

dtype=None,

optional, Datentyp aller array-Elemente

copy=True,

wenn False, wird eine Kopie von „object“ nur wenn unbedingt notwendig erzeugt

order=None,

Anordnung der Elemente; 'A': Vorgabe, wie „object“ (auße bei Kopie, dann wie 'C'), 'C': wie in C (letzter Index läuft am schnellsten), 'F': wie in FORTRAN (1. Index läuft am schnellsten ) wichtig zur Code-Optimiereung !

subok=False, ndmin=0

Vorgabe Basis-Klasse ist array, ansonsten kann eine von der Basis-Klasse von „object“ geerbt werden (z.B. von np.mat) minimale Dimension des arrays (ggf. Voranstellen von Einsen)

)¶ einfachste und häufigste Variante:

a=np.array( [ ] )

Beispiele zu numpy >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.array([1,2,4],'int') >>> y array([1, 2, 4]) >>> z = np.arange(3, 'uint8') >>> z array([0, 1, 2], dtype=uint8)

numpy-arrays können mitverschiedenen Datentypen initialisiert werden allerdings enthält ein array immer Elemente vom gleichen Typ Datentypen: bool, int,int8,int16,int32 int64,uint8,uint16,uint32,uint64, float,float16,float32,float64, complex, complex64,complex128 s. Anhang zu Datentypen

>>> np.zeros(5) ← Initialisieren mit 0 array([ 0., 0., 0., 0., 0.]) >>> np.zeros((2,3)) ← 2-dim array array([[ 0., 0., 0.], [ 0., 0., 0.]]) ← Zahlen in Bereich mit Schrittweite >>> np.arange(2, 3, 0.1) array([ 2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9]) >>> np.linspace(1., 4., 6) ← Zahlen in Bereich mit Anzahl, obere Grenze enthalten array([ 1., 1.6, 2.2, 2.8, 3.4, 4. ])

Beispiele zu numpy (2) Berechnung des gewichteten Mittelwerts import numpy as np w = 1/sx**2 sumw = np.sum(w) mean = np.sum(w*x)/sumw smean = np.sqrt(1./sumw)

Diskrete Fourier-Transformation import numpy as np # input vectors a, t n = len(t) dt = (t[-1]-t[0])/(n-1.) # time step freq = np.linspace(0., 0.5/dt, n/2) omegat=np.outer(2.*np.pi*freq, t) s = np.matmul( np.sin(omegat), a) / n c = np.matmul( np.cos(omegat), a ) / n

Zufall aus dem Computer numpy erlaubt es auch, Arrays (also Vektoren und Matrizen) mit Zufallszahlen zu füllen: gleichverteilte Zufallszahlen >>> np.random.rand() 0.466210425430829 >>> np.random.rand() 0.3937425857019299 >>> np.random.rand() gleiche Funktion, aber 0.8586162430715967 jedes mal eine andere Zahl ! >>> np.random.rand() 0.31812462303570166 >>> np.random.rand(3) array([ 0.43266661, 0.76177195, 0.60922989])

normal-verteilte Zufallszahlen >>> np.random.randn() 0.5224185337307578 >>> np.random.randn() 1.8467581564176467 >>> np.random.randn(2) array([-0.47682414, -0.59424037])

matplotlib für's Auge siehe

http://www.matplotlib.org

matplotlib user guide: „ making plots should be easy!“

Einfaches Beispiel numpy & matplotlib >>> >>> >>> >>> >>> >>> >>> >>>

import numpy as np import matplotlib.pyplot as plt x=np.linspace(-20,20,200) y=np.sin(x)/x plt.plot(x,y) plt.show()

schöne Grafiken mit matplotlib Mit sehr wenig Aufwand kann man auch Beschriftungen und weitere Grafikelemente hinzufügen (s. Aufg. Blatt 3):

Grafische Ausgabe des Scripts FunctionPlotter.py – gibt es nach Blatt 3 ...

matplotlib Grundlagen matplotlib einfügen

import matplotlib.pyplot as plt

Balkendiagramm

h = [3., 5., 4., 2.] x = [1., 2., 3., 4.] plt.bar(x, y)

Grafik anzeigen

plt.show()

Häufigkeitsverteilung

Daten mit Fehlerbalken

a = [1, 1, 2, 3, 3, 3, 4, 4] plt.hist(a, 4)

x = [1., 2., 3., 4.] y = [3., 5., 4., 2.] e = 0.5 plt.errorbar(x, y, yerr=e, fmt='ro') Noch nicht sehr schön, aber das kriegen wir noch ...

Falsche Daten # Messdaten = Model + Messfehler import numpy as np import matplotlib.pyplot as plt def model(x, a=1., b=0.5): return a*x+b

numpy.random bietet Erzeugung von Zufallszahlen matplotlib (.pyplot.errorbar) erlaubt Darstellung von Datenpunkten mit Fehlerbalken

# generate fake data according to model npoints, err =10, 1.3 xmin,xmax=1., 10. xm=np.linspace(xmin,xmax,npoints) ← Erzeugung normalverteilter dy=err*np.random.normal(size=npoints) ← Erzeugung von Zufallszahlen Zufallszahlen ym=model(xm)+dy (normalverteilt) # plot model dx=(xmax-xmin)/10. x=np.linspace(xmin-dx,xmax+dx,200) plt.plot(x,model(x),'r-')

#plot fakde data ← Darstellung von Messplt.errorbar(xm,ym,yerr=err,fmt='bo') ← Darstellung von Datenpunkten plt.show() # display on screen punkten mit Fehlern

mit Fehlerbalken

Häufigkeiten sichtbar: Histogramm import numpy as np import matplotlib.pyplot as plt # generate random normal-distributed numbers data=np.random.normal(size=100) # plot data as historgram plt.hist(data,50,normed=1) ← Häufigkeitsverteilung in plt.show() # put on screen

numpy.random bietet Erzeugung von Zufallszahlen matplotlib (.pyplot.hist) bietet Erzeugung und Darstellung von Häufigkeitsverteilungen

50 Intervallen

noch schöneres Bild import numpy as np import matplotlib.pyplot as plt def fgauss(x,norm=1.,mu=0.,sigma=1.): # define Gauss-function return (norm*np.exp(-(x-mu)**2/2/sigma**2)/np.sqrt(2*np.pi)/sigma) data=np.random.normal(size=100) # generate Gaussian random data #plot function and data x = np.arange(-4., 4., 0.1) plt.plot(x, fgauss(x), 'r-') plt.hist(data,50,normed=1) # make plot nicer: plt.xlabel('x') # add labels plt.ylabel('probability density') plt.title('Gauss distribution') plt.figtext(0.6, 0.8 \ ,r'$f(x) = N(\mu=0.,\sigma=1.)$'\ ,fontsize=14, color='r') # nice formula plt.grid(True) # show a grid plt.show() # on screen

← mit LaTeX beschriftete Grafik

Animierte Grafiken mit matplotlib Hilfe des Pakets matplotlib.animation können auch animierte Grafiken erstellt werden,

Mit

s. Script animated_Coin.py

Würfeln mit Animation und noch ein „nützliches“ Script: animations/playDice.py

höhere Mathematik: SciPy

SciPy enthält viele weitere nützliche Pakete für das wissenschaftliche Rechnen http://www.scipy.org

spezielle mathematische Funktionen & Algorithmen aus den Bereichen – Statistik – numerische Integration – numerische Optimierung – Interpolation – Signalverarbeitung (incl. FFT) – lineare Algebra – ...

Einschub:

python-Programmierung

Spätestens wenn Sie auf dem Niveau von scipy angekommen sind, sind Ihre Ergebnisse auch für andere interessant. Sie sollten sich damit beschäftigen, wie Sie Ihren Code so schreiben und dokumentieren, so dass er für andere (und für Sie selbst) verständlich, nachvollziehbar und vertrauenswürdig ist. Bei umfangreichen Projekten empfiehlt sich die Angabe einer Lizenz, die dafür sorgt, dass Ihr Code nur nach den dort festgelegten Regeln verwendet, weitergegeben oder verändert werden darf. Sie könnten Ihren Code z. B. als freie Software unter die Gnu Public Licence (GPB) stellen. Dies verhindert auch, dass Sie von unbedarften Anwendern für die mit Ihrem Code erzielten Ergebnisse haftbar gemacht werden können.

Wichtige WichtigeStichpunkte: Stichpunkte: ––(aussagekräftige) (aussagekräftige)Kommentarzeilen Kommentarzeilen!!!!!! ––Angabe Angabevon vonAutor Autor(und (undevtl. evtl.Lizenzbestimmungen) Lizenzbestimmungen) ––Dokumentation, Dokumentation,möglichst möglichstso, so,dass dasssie sieautomatisiert automatisiertaus ausdem demQuellcode Quellcode erstellt werden kann (s. google docstrings & sphinx im 3. Vorlesungsblock) erstellt werden kann (s. google docstrings & sphinx im 3. Vorlesungsblock) –– evtl. evtl.Bereitstellung Bereitstellungeiner einerkleinen kleinenHilfe-Funktion Hilfe-Funktion ––einfaches nach einfachesAnwendungsbeispiel, Anwendungsbeispiel,kann kannauch auchals alsautomatisierter automatisierterTest Test(z.B. (z.B. nach Veränderungen, Erweiterungen) genutzt werden (s. unittests im 3. Vorlesungsblock) Veränderungen, Erweiterungen) genutzt werden (s. unittests im 3. Vorlesungsblock) ––Unterstützung Unterstützungdes desimports importsvon vonFunktionen Funktionenininandere andereProgramme Programme

Special Funcions: scipy.special Dokumentation, kann in dieser Form z.B. mit Hilfe von sphinx in ein (html-)Dokument eingebunden werden

"""scipy_example.py Compute the maximum of a Bessel function and plot it. Source: https://www.scipy.org/getting-started.html """ import argparse import numpy as np, matplotlib.pyplot as plt from scipy import special, optimize

(schönes und professionelles) Beispielscript von http://www.scipy.org

def main(): # Parse command-line arguments interface mit Hile für die Kommando-Zeilen parser = argparse.ArgumentParser(usage=__doc__) parser.add_argument("--order", type=int, default=3, help="order of Bessel function") parser.add_argument("--output", default="plot.png", help="output image file") args = parser.parse_args() # Compute maximum f = lambda x: -special.jv(args.order, x) sol = optimize.minimize(f, 1.0) # Plot x = np.linspace(0, 10, 100) plt.plot(x, special.jv(args.order, x), '-', sol.x, -sol.fun, 'o') # Produce output plt.savefig(args.output, dpi=96) if __name__ == "__main__": main()

Code ab heri wird bei import nicht ausgeführt (nützlich für test oder Anwendungsbeispiel)

Suche des Maximums einer Bessel-Funktion und grafische Darstellung

Differentialgleichungen lösen mit scipy import numpy as np, matplotlib.pyplot as plt from scipy.integrate import odeint mass = 0.5 kspring = 4 cdamp = 0.4

Auszug aus Script odeint_scillators.py

nu_coef = cdamp / mass om_coef = kspring / mass def deriv_lindamp(yvec, time, nuc, omc): ''' calculate derivatives: x´=v, v´=x´´ ''' return (yvec[1], -nuc * yvec[1] - omc * yvec[0])

Paket scipy.odeint löst Systeme von Differentialgleichungen erster Ordnung numerisch. Differentialgleichungen höherer Ordnung werden auf ein System von Gleichungen 1. Ordnung transformiert:

# parameters for numerical solution tmax=50. # time span dt=0.1 # time step time_vec = np.linspace(0, tmax, int(tmax/dt)) # initial conditions a0=1. v0=0. # get solution vector from odeint arr_lindamp = odeint(deriv_lindamp, (a0,v0), time_vec, args=(nu_coef, om_coef)) fig=plt.figure(figsize=(10., 10.)) ax=fig.add_subplot(2,2,1) ax.text(0.5, 0.05, 'linear damping', transform=ax.transAxes) ax.plot(time_vec, arr_lindamp[:, 0], label='amplitude') ax.plot(time_vec, arr_lindamp[:, 1], label="velocity") ax.legend() plt.show()

Beispiel: linear gedämpfter harmonischer Oszillator

Differentialgleichungen lösen mit scipy (2) Paket scipy.odeint Script odeint_oscillators.py

Wenn man die DifferentialGleichung ändert, löst der gleiche Code die Bewegungsgleichungen für alle möglichen Arten von (nicht-linearen) Oszillatoren.

scipy.odeint in Beispiel mit Animation mit recht wenig Aufwand funktioniert auch das Lösen von Differentialgleichungssystemen in Echtzeit, z. B. das aus Theorie B bekannte (chaotische) Doppelpendel. Mit dem Paket matplotlib.animation lässt sich das auch als animierte Grafik darstellen: s. Script animations/double_pendulum.py

Es gibt noch viel zu entdecken ! Einfach ausprobieren ... Beste Methode: Beispiele – analysieren, – für eigene Zwecke anpassen, – weiterentwickeln.

Anhang: Datenformate

Zahlendarstellung (digitale) Daten bestehen aus einzelnen „Bits“ (=Ziffern einer Dualzahl); – in Kontroll-Registern sind einzelne Bits bedeutsam; – für komplexere Datenstrukturen werden Bits üblicherweise in Vierergruppen zu einem „Hex-Digit“ kombiniert (üblich ist auch die oktale Darstellung) dez. 00 01 02 03 04 05 06 07

binär 0000 0001 0010 0011 0100 0101 0110 0111

Hex 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7

oktal 0o00 0o01 0o02 0o03 0o04 0o05 0o06 0o07

dez. 08 09 10 11 12 13 14 15

binär 1000 1001 1010 1011 1100 1101 1110 1111

Hex 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF

Üblich ist 1 Byte = 8 Bits = 2 HexDigits als Einheit

oktal 0o10 0o11 0o12 0o13 0o14 0o15 0o16 0o17

Negative Zahlen Für ganze Zahlen mit Vorzeichen wird das höchstwertige Bit als Vorzeichen-Bit betrachtet; Darstellung als sog. „Zweierkomplement:“ positive Zahl p, dann ist -p = invertierte Bits + 1

Dez -8 -7 -6 -5 -4 -3 -2 -1

binär 1000 1001 1010 1011 1100 1101 1110 1111

Hex 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF

oktal 0o10 0o11 0o12 0o13 0o14 0o15 0o16 0o17

Vorteil: Subtraktion entspricht Addition des 2-Komplements

Ganze Zahlen In der Praxis reicht ein Byte meist nicht aus, komplexere Datentypen entstehen durch Aneinanderreihung von Bytes:

Wertebereich 0 bis 255

Byte 7

Halbwort ohne Vorzeichen Halbwort mit Vorzeichen Wort ohne Vorzeichen

Wort mit Vorzeichen

0

(-128 bis 127 mit Vorzeichen)

0 bis 65.535 15

0

-32.768 bis 32.767

S 15

0

0 bis 4.294.967.295 31

0

S 31

0

–2.147.483.648 bis 2.147.483.647

Ganze Zahlen, Text Wertebereich

63

Doppelwort mit Vorzeichen ASCII alphanumerische Zeichen

BCD = binary coded decimal

packed BCD

32

S

0

31

0

char3

char2

char1

char0 0

31

0 n3 0

n2

0

n1

n7 n6 n5 n4

0 n0

0 bis 9.999

0

31

31

~-0.9 x 1019 bis ~0.9 x 1019

n3

n2

n1 n0 0

0 bis 99.999.999

Reelle Zahlen Reelle Zahlen werden beschrieben durch ein Vorzeichen s, eine Mantisse m, einen Exponenten e und eine konstante Verschiebung b:

Z = (-1)s · 1,m · 2e-b Werte- Genauigkeit in bereich Dezimalstellen float 32 (single precision)

S

ca. ±10±38

mantisse

31

0

63

32

float64 (double precision)

exp.

S 31

mantisse 1 exponent mantisse 2

ca. ±10±308 0 0

es gibt auch „quadruple precision“ mit 128 Bits

Spezielle Bitmuster für 0, ±∞ d.h. ungültige Zahl (NaN)

7-8

15 - 16

Vektorformate z.B.:

63

32

31

0

127 127

96 96

Bitfeld mit 4*16

Bitfeld mit 4 float32 31

0

Moderne Prozessoren unterstützen SIMD (=“Singel Instruction Multiple Data“) Befehle: führen die selbe Operation auf allen Teilwörtern aus

Speicheranordnung ... ... ist leider nicht einheitlich ! „big-endian“ Wortaddresse Stelle des Byte im Wort

x0 7 6

5

4

x4 3

2

1

0

3

x4 4

5

6

7

„little-endian“ Wortaddresse Stelle des Byte im Wort

x0 0 1

2

x86-Architektur verwendet little-endian ! Wichtig bei Datentransfers von / zu anderen Plattformen ! Datentyp, zu dem ein Byte gehört, muss bekannt sein.

Text – ASCII Format

Erweitertes ASCII-Format Erweiterung des Ascii-Standards um graphische und nationale Sonder-Zeichen

Leider nicht ganz einheitlich gehandhabt.

Text in Unicode Ziel: Codierung aller in Gebrauch befindlichen Schriftsysteme - 17 Ebenen mit je 216 Zeichen (6 z. Zt. im Gebrauch)

Unicode Ebene 0 - BMP Basic Multilingual Plane

(Quelle: Wikipedia) Beispiele: – UTF-8 (7-bit ascii kompatibel) nutzt variable Länge von 1-4 Bytes zur Codierung aller Unicode-Zeichen, weit verbreitet im WWW und bei E-Mail – Microsoft nutzt Spezialformat mit 2 Bytes/Zeichen

ascii-Text im Speicher > hexdump 00000000 00000010 00000020 00000030 00000040 00000050 00000060 00000070 00000080 00000090 000000a0 000000b0 000000c0 000000d0 000000e0 000000f0 00000100 00000110 00000120 00000130 00000140 00000150

-C 48 68 73 69 75 72 20 68 6e 6f 6c 72 72 67 68 20 72 20 fc 20 2c 20

Faust.txt 61 62 65 20 69 6c 6f 73 74 65 72 65 6e 2c 0a 55 63 68 20 54 63 68 61 75 6d 69 74 20 6e 2e 0a 44 75 6e 2c 20 72 21 0a 55 75 67 20 61 3b 0a 48 65 2c 20 68 65 61 72 0a 55 6f 6e 20 61 4a 61 68 72 61 62 20 75 6b 72 75 6d 6c 65 72 20 68 65 72 75 20 64 61 df 77 69 73 73

6e 6f 69 6e 68 73 68 61 69 6e 6c 69 69 6e 6e 0a 6e 6d 61 6d 20 65

75 70 20 64 65 20 65 20 63 64 73 df df 64 20 48 64 0a 6e 2d 77 6e

6e 68 75 20 6f 73 69 73 68 20 20 65 65 20 64 65 20 4d 20 0a 69 20

2c 69 6e 6c 6c 74 df 74 20 62 77 20 20 7a 69 72 71 65 64 55 72 6b

20 65 64 65 6f 75 65 65 61 69 69 4d 44 69 65 61 75 69 65 6e 20 f6

61 2c 20 69 67 64 6d 68 72 6e 65 61 6f 65 20 75 65 6e 72 64 6e 6e

63 0a 4d 64 69 69 20 20 6d 20 20 67 6b 68 7a 66 72 65 20 20 69 6e

68 4a 65 65 65 65 42 69 65 73 7a 69 74 65 65 2c 20 20 4e 73 63 65

21 75 64 72 0a 72 65 63 72 6f 75 73 6f 20 68 20 75 53 61 65 68 6e

20 72 69 20 44 74 6d 68 20 20 76 74 72 73 65 68 6e 63 73 68 74 21

50 69 7a 61 75 2c fc 20 54 6b 6f 65 20 63 6e 65 64 68 65 65 73 0a

|Habe nun, ach! P| |hilosophie,.Juri| |sterei und Mediz| |in,.Und leider a| |uch Theologie.Du| |rchaus studiert,| | mit heißem Bemü| |hn..Da steh ich | |nun, ich armer T| |or!.Und bin so k| |lug als wie zuvo| |r;.Heiße Magiste| |r, heiße Doktor | |gar.Und ziehe sc| |hon an die zehen| | Jahr.Herauf, he| |rab und quer und| | krumm.Meine Sch| |üler an der Nase| | herum-.Und sehe| |, daß wir nichts| | wissen können!.|

Datenformate Nahezu jede Anwendung bringt ihr eigenes Datenformat mit (Word, Excel, LibreOffice, ...) führt zu unendlichen Kompatibilitätsproblemen. Jeder C++-Klasse entspricht im Prinzip einem eigenen „Datenformat“; Methoden der Klasse sind für die Prozessierung der Daten (Drucken, Speichern, Verarbeiten, Konvertieren, ...) zuständig

Viele moderne Datenformate bauen auf ascii auf SGML, HTML, XML ... recht gut lesbar, nahezu selbst-dokumentierend, aber Speicher-aufwändig ( die Ziffernfolge „12345678“ benötigt 8 Bytes, die dargestellte Zahl aber nur 3 !) Komprimierungsverfahen (z.B. „ZIP“) helfen, den zusätzlichen Speicherbedarf erträglich zu halten.