#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
(Beginn eines langen Kommentars)
Python Skript, das Naturkonstanten einliest und Groessenordnungen
abschaetzt.
Im Interpreter-Modus aufrufen mit
>>> execfile('orders-of-magnitude.py')
(Ende eines langen Kommentars)
"""

from scipy.constants import physical_constants as const
from scipy.constants import pi, find
# example: find('Planck')
from scipy import real, imag, sqrt

# Konstanten definieren. *Achtung!* Keine automatische Ueberpruefung
# der Einheiten! Die kann man z.B. mit
# const['electric constant'][1]
# ansehen.
eps0 = const['electric constant'][0]
mu0 = const['mag. constant'][0]
c = const['speed of light in vacuum'][0]
hbar = const['Planck constant over 2 pi'][0]
kB = const['Boltzmann constant'][0]
e0 = const['elementary charge'][0]
amu = const['unified atomic mass unit'][0]
me = const['electron mass'][0]
a0 = const['Bohr radius'][0]
G = const['Newtonian constant of gravitation'][0]
mW = 1e-3
cm = 1e-2
# gute Praxis: Formeln fuer dimensionsbehaftete Groessen so 
# schreiben, dass man die Dimension 'sehen' kann
micron = 1e-4*cm 
nm = 1e-3*micron

# mit if True: und if False: kann man eine 'Aufgabe' einfach
# ausblenden
if True:
   # light intensity (time-averaged) and electric field
   Int = 100.*1e-3/(1e-4) # intensity in mW/cm^2 and W/m^2
   field = sqrt(Int/(2*eps0*c)) # field amplitude in V/m
   #
   print('field with I = %4.4g mW/cm^2: amplitude %4.4g V/m' %(Int/(mW/cm**2), field))
   # mit dieser 'print' Konstruktion werden Zahlenwerte formatiert
   # ausgegeben: 4.4 heisst etwa vier Nachkommastellen, g heisst flexibles
   # umschalten mit/ohne Zehnerpotenzen

   # field inside an atom
   dist = a0 # Bohr radius
   field = e0/(4*pi*eps0*dist**2)
   print('field at r = %4.4g a_0: amplitude %4.4g V/m' %(dist/a0, field))