first work on julia engine branch
This commit is contained in:
parent
cbfdbaa4eb
commit
cc79833992
17
_extensions/MHellmund/julia-color/_extension.yml
Normal file
17
_extensions/MHellmund/julia-color/_extension.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: Julia-color
|
||||
author: Meik Hellmund
|
||||
version: 1.0.0
|
||||
quarto-required: ">=99.9.0"
|
||||
contributes:
|
||||
formats:
|
||||
common:
|
||||
filters:
|
||||
- "ansi2htmltex.lua"
|
||||
html:
|
||||
monofont: "JuliaMono"
|
||||
css:
|
||||
- "resources/css/ansicolor.css"
|
||||
- "resources/css/juliamono.css"
|
||||
pdf:
|
||||
include-in-header:
|
||||
- "resources/tex/juliainc.tex"
|
@ -1,10 +1,5 @@
|
||||
-- this is essentially
|
||||
-- based on
|
||||
-- https://github.com/jupyter/nbconvert/blob/main/nbconvert/filters/ansi.py
|
||||
-- converted to lua
|
||||
|
||||
-- good list of ANSI escape sequences:
|
||||
-- https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
|
||||
|
||||
|
||||
local ANSI_COLORS = {
|
||||
"ansi-black",
|
||||
@ -60,18 +55,8 @@ local function get_extended_color(numbers)
|
||||
return {r, g, b}
|
||||
end
|
||||
|
||||
|
||||
--[=[
|
||||
local re = require "re"
|
||||
|
||||
local ANSI = re.compile [[
|
||||
'\x1b%[' {.*?} {[@-~]}
|
||||
]]
|
||||
|
||||
--]=]
|
||||
|
||||
local function LaTeXconverter(fg, bg, bold, underline, inverse)
|
||||
if not (fg or bg or bold or underline or inverse) then
|
||||
local function LaTeXconverter(fg, bg, bold, light, italic, underline, inverse)
|
||||
if not (fg or bg or bold or light or italic or underline or inverse) then
|
||||
return "",""
|
||||
end
|
||||
|
||||
@ -116,6 +101,16 @@ local function LaTeXconverter(fg, bg, bold, underline, inverse)
|
||||
endtag = "}" .. endtag
|
||||
end
|
||||
|
||||
if light then
|
||||
starttag = starttag .. [[\textlight{]]
|
||||
endtag = "}" .. endtag
|
||||
end
|
||||
|
||||
if italic then
|
||||
starttag = starttag .. [[\textit{]]
|
||||
endtag = "}" .. endtag
|
||||
end
|
||||
|
||||
if underline then
|
||||
starttag = starttag .. [[\underline{]]
|
||||
endtag = "}" .. endtag
|
||||
@ -123,8 +118,8 @@ local function LaTeXconverter(fg, bg, bold, underline, inverse)
|
||||
return starttag, endtag
|
||||
end
|
||||
|
||||
local function HTMLconverter(fg, bg, bold, underline, inverse)
|
||||
if not (fg or bg or bold or underline or inverse) then
|
||||
local function HTMLconverter(fg, bg, bold, light, italic, underline, inverse)
|
||||
if not (fg or bg or bold or light or italic or underline or inverse) then
|
||||
return "",""
|
||||
end
|
||||
local classes = {}
|
||||
@ -156,6 +151,14 @@ local function HTMLconverter(fg, bg, bold, underline, inverse)
|
||||
table.insert(classes, "ansi-bold")
|
||||
end
|
||||
|
||||
if light then
|
||||
table.insert(classes, "ansi-light")
|
||||
end
|
||||
|
||||
if italic then
|
||||
table.insert(classes, "ansi-italic")
|
||||
end
|
||||
|
||||
if underline then
|
||||
table.insert(classes, "ansi-underline")
|
||||
end
|
||||
@ -196,7 +199,8 @@ local function codeBlockTrans(e)
|
||||
|
||||
local texenv="OutputCell"
|
||||
local codeclass=""
|
||||
if string.find(e.text, "\u{a35f}\u{2983}") then
|
||||
-- if string.find(e.text, "\u{a35f}\u{2983}") then
|
||||
if string.find(e.text, "\x1b%[") then
|
||||
texenv = "AnsiOutputCell"
|
||||
codeclass = "ansi"
|
||||
end
|
||||
@ -206,12 +210,18 @@ local function codeBlockTrans(e)
|
||||
end
|
||||
|
||||
local out=""
|
||||
-- if string.find(e.text, "\x1b%[") then
|
||||
if string.find(e.text, "\u{a35f}\u{2983}") then
|
||||
local text = e.text
|
||||
|
||||
-- we remove links (eg in julia ParseErrors. THey link to local files, so they are useless anyway)
|
||||
text = text:gsub("\x1b%]8;.-\x1b\\", "")
|
||||
|
||||
if string.find(text, "\x1b%[") then
|
||||
-- if string.find(text, "\u{a35f}\u{2983}") then
|
||||
local bold = false
|
||||
local light = false
|
||||
local italic = false
|
||||
local underline = false
|
||||
local inverse = false
|
||||
local text = e.text
|
||||
local chunk = ""
|
||||
local fg = nil
|
||||
local bg = nil
|
||||
@ -221,8 +231,9 @@ local function codeBlockTrans(e)
|
||||
|
||||
while text ~= "" do
|
||||
numbers = {}
|
||||
-- local s1, e1, c1, d1 = string.find(text, "\x1b%[(.-)([@-~])")
|
||||
local s1, e1, c1, d1 = string.find(text, "\u{a35f}\u{2983}(.-)([@-~])")
|
||||
-- [@-~]: matches single char between 64 and 126
|
||||
local s1, e1, c1, d1 = string.find(text, "\x1b%[(.-)([@-~])")
|
||||
-- local s1, e1, c1, d1 = string.find(text, "\u{a35f}\u{2983}(.-)([@-~])")
|
||||
if s1 then
|
||||
if d1 == "m" then
|
||||
for i in string.gmatch(c1, "([^;]*)") do
|
||||
@ -238,9 +249,9 @@ local function codeBlockTrans(e)
|
||||
|
||||
if chunk ~= "" then
|
||||
if bold and type(fg)=="number" and fg<8 then
|
||||
starttag, endtag = converter(fg+8, bg, bold, underline, inverse)
|
||||
starttag, endtag = converter(fg+8, bg, bold, light, italic, underline, inverse)
|
||||
else
|
||||
starttag, endtag = converter(fg, bg, bold, underline, inverse)
|
||||
starttag, endtag = converter(fg, bg, bold, light, italic, underline, inverse)
|
||||
end
|
||||
out = out .. starttag .. chunk .. endtag
|
||||
end
|
||||
@ -253,20 +264,26 @@ local function codeBlockTrans(e)
|
||||
bold = false
|
||||
inverse = false
|
||||
underline = false
|
||||
elseif n == 1 then
|
||||
elseif n == 1 or n == 5 or n == 6 then -- bold and blink
|
||||
bold = true
|
||||
elseif n == 2 or n == 8 then -- 'dim' and 'hide'
|
||||
light = true
|
||||
elseif n == 3 then
|
||||
italic = true
|
||||
elseif n == 4 then
|
||||
underline = true
|
||||
elseif n == 5 then
|
||||
bold = true -- 'blinking'
|
||||
elseif n == 7 then
|
||||
inverse = true
|
||||
elseif n == 21 or n == 22 then
|
||||
elseif n == 21 or n == 22 or n == 25 then
|
||||
bold = false
|
||||
elseif n == 23 then
|
||||
italic = false
|
||||
elseif n == 24 then
|
||||
underline = false
|
||||
elseif n == 27 then
|
||||
inverse = false
|
||||
elseif n == 22 or n == 28 then
|
||||
light = false
|
||||
elseif n >= 30 and n <= 37 then
|
||||
fg = n - 30
|
||||
elseif n == 38 then
|
||||
@ -290,7 +307,7 @@ local function codeBlockTrans(e)
|
||||
end
|
||||
end
|
||||
else
|
||||
out = e.text
|
||||
out = text
|
||||
end
|
||||
if fmt == 'html' then
|
||||
return pandoc.RawBlock(fmt,
|
||||
@ -324,67 +341,13 @@ local function divCodeBlockNoHeader1(e)
|
||||
for i, el in pairs(c) do
|
||||
if el.t == 'Header' then
|
||||
el.level = 6
|
||||
-- elneu = pandoc.Para(el.content)
|
||||
-- c[i] = elneu
|
||||
end
|
||||
if el.t == 'CodeBlock' then
|
||||
if el.classes:includes("jldoctest") then
|
||||
x,i = el.classes:find("jldoctest")
|
||||
el.classes:remove(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
return e
|
||||
end
|
||||
|
||||
-- test if two divs should be merged
|
||||
local function testmerge(d1, d2)
|
||||
return d1 and d1.t == "Div" and d1.classes:includes("cell-output") and #d1.content == 1
|
||||
and d2 and d2.t == "Div" and d2.classes:includes("cell-output") and #d2.content == 1
|
||||
and d1.content[1].t == "CodeBlock" and not d1.classes:includes("cell-output-stderr")
|
||||
and d2.content[1].t == "CodeBlock" and not d2.classes:includes("cell-output-stderr")
|
||||
end
|
||||
|
||||
-- merge (div (codecell (text1)), div (codecell(text2))) to div(codecell(text1+text2))
|
||||
local function blockMerge(es)
|
||||
local nl = ""
|
||||
for i = #es-1, 1, -1 do
|
||||
if testmerge(es[i], es[i+1]) then
|
||||
str1 = es[i].content[1].text
|
||||
str2 = es[i+1].content[1].text
|
||||
nl = "\n"
|
||||
if es[i].classes:includes("cell-output-stdout") and es[i+1].classes:includes("cell-output-stdout") then
|
||||
if str1:sub(-1) == "\n" then
|
||||
nl = ""
|
||||
end
|
||||
if str2:sub(1, 1) == "\n" then
|
||||
nl = ""
|
||||
end
|
||||
end
|
||||
es[i].content[1].text = str1 .. nl .. str2
|
||||
es:remove(i+1)
|
||||
end
|
||||
end
|
||||
return es
|
||||
end
|
||||
|
||||
local function metaAdd(meta)
|
||||
--for key, val in pairs(PANDOC_READER_OPTIONS) do
|
||||
-- quarto.log.warning(key, val)
|
||||
--end
|
||||
quarto.doc.addHtmlDependency({name='ansicolors',
|
||||
stylesheets = {'resources/css/ansicolor.css'}})
|
||||
quarto.doc.addHtmlDependency({name='juliamonofont',
|
||||
stylesheets = {'resources/css/juliamono.css'}})
|
||||
if quarto.doc.isFormat('latex') then
|
||||
quarto.doc.include_file("in-header", "resources/juliainc.tex")
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{Div = divStderr},
|
||||
{Div = divCodeBlockNoHeader1},
|
||||
{Blocks = blockMerge},
|
||||
{CodeBlock = codeBlockTrans},
|
||||
{Meta = metaAdd}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
/* CSS added by ANSI escape sequences filter */
|
||||
|
||||
.ansi {
|
||||
/* line-height:1.15; */
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
@ -46,5 +45,8 @@ pre .ansi-cyan-intense-bg { background-color: #258f8f; }
|
||||
pre .ansi-white-intense-bg { background-color: #a1a6b2; }
|
||||
pre .ansi-default-inverse-fg { color: rgba(255, 255, 255, 1); }
|
||||
pre .ansi-default-inverse-bg { background-color: #111111; }
|
||||
pre .ansi-bold { font-weight: bold; }
|
||||
pre .ansi-bold { font-weight: 800; }
|
||||
pre .ansi-light { font-weight: 300; }
|
||||
pre .ansi-italic { font-style: italic; }
|
||||
pre .ansi-underline { text-decoration: underline; }
|
||||
|
110
_extensions/MHellmund/julia-color/resources/css/juliamono.css
Normal file
110
_extensions/MHellmund/julia-color/resources/css/juliamono.css
Normal file
@ -0,0 +1,110 @@
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 300;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Light.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Regular.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Medium.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 600;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-SemiBold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Bold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 800;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-ExtraBold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 900;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Black.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 300;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-LightItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 400;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-RegularItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 500;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-MediumItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 600;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-SemiBoldItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 700;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-BoldItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 800;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-ExtraBoldItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 900;
|
||||
font-style: italic;
|
||||
src: url("../fonts/JuliaMono-BlackItalic.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,9 +8,15 @@
|
||||
BoldFont = *-Bold,
|
||||
ItalicFont = *-RegularItalic,
|
||||
BoldItalicFont = *-BoldItalic,
|
||||
FontFace={l}{n}{Font=*-Light},
|
||||
FontFace={l}{it}{Font=*-LightItalic},
|
||||
Contextuals = AlternateOff,
|
||||
]
|
||||
|
||||
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
|
||||
\DeclareTextFontCommand{\textlight}{\lseries}
|
||||
|
||||
|
||||
\DefineVerbatimEnvironment{OutputCell}{Verbatim}%
|
||||
{xleftmargin=1.5em}
|
||||
\DefineVerbatimEnvironment{AnsiOutputCell}{Verbatim}%
|
||||
@ -35,4 +41,4 @@
|
||||
\definecolor{ansi-white}{HTML}{C5C1B4}
|
||||
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
|
||||
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
|
||||
\definecolor{ansi-default-inverse-bg}{HTML}{000000}
|
||||
\definecolor{ansi-default-inverse-bg}{HTML}{000000}
|
@ -1,15 +0,0 @@
|
||||
title: Extensions for Julia
|
||||
author: Meik Hellmund
|
||||
version: 0.3.0
|
||||
contributes:
|
||||
format:
|
||||
common:
|
||||
filters:
|
||||
- ansi2htmltex.lua
|
||||
ipynb-filters:
|
||||
- escfilter.py
|
||||
pdf:
|
||||
default
|
||||
|
||||
html:
|
||||
monofont: "JuliaMono"
|
@ -1,5 +0,0 @@
|
||||
import sys
|
||||
f = sys.stdin.read()
|
||||
g = f.replace('\\u001b[','ꍟ⦃').replace('\\u001b]8;;','').replace('\\u001b\\\\','')
|
||||
sys.stdout.write(g)
|
||||
|
@ -1,55 +0,0 @@
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 300;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Light.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Regular.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Medium.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 600;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-SemiBold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Bold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 800;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-ExtraBold.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: JuliaMono;
|
||||
font-weight: 900;
|
||||
font-style: normal;
|
||||
src: url("../fonts/JuliaMono-Black.woff2") format("woff2");
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27
_quarto.yml
27
_quarto.yml
@ -42,20 +42,22 @@ book:
|
||||
chapters:
|
||||
- index.qmd
|
||||
- chapters/entwicklungsumgebungen.qmd
|
||||
- chapters/first_contact.qmd
|
||||
- chapters/Erste_Bsp.qmd
|
||||
# - chapters/first_contact.qmd
|
||||
# - chapters/Erste_Bsp.qmd
|
||||
- chapters/syntax.qmd
|
||||
- chapters/5_TricksHelp.qmd
|
||||
- chapters/numerictypes.qmd
|
||||
- chapters/Pi2.qmd
|
||||
- chapters/types.qmd
|
||||
- chapters/pcomplex.qmd
|
||||
- chapters/9_functs.qmd
|
||||
# - chapters/types.qmd
|
||||
# - chapters/pcomplex.qmd
|
||||
# - chapters/9_functs.qmd
|
||||
- chapters/6_ArraysEtcP1.qmd
|
||||
- chapters/7_ArraysP2.qmd
|
||||
- chapters/11_LinAlg.qmd
|
||||
- chapters/10_Strings.qmd
|
||||
- chapters/14_Plot.qmd
|
||||
# - chapters/7_ArraysP2.qmd
|
||||
# - chapters/11_LinAlg.qmd
|
||||
# - chapters/10_Strings.qmd
|
||||
# - chapters/14_Plot.qmd
|
||||
# - chapters/13_IO.qmd
|
||||
|
||||
# - chapters/makie.qmd
|
||||
# - chapters/ablaufsteuerung.qmd
|
||||
# - chapters/example.qmd
|
||||
@ -64,7 +66,7 @@ book:
|
||||
|
||||
|
||||
format:
|
||||
julia-html:
|
||||
julia-color-html:
|
||||
theme:
|
||||
light: [cosmo, css/light.scss]
|
||||
dark: [superhero, css/dark.scss]
|
||||
@ -84,9 +86,9 @@ format:
|
||||
body-width: 1150px # 800
|
||||
margin-width: 250px
|
||||
gutter-width: 1.5em
|
||||
cap-location: bottom
|
||||
cap-location: bottom
|
||||
|
||||
julia-pdf:
|
||||
julia-color-pdf:
|
||||
pdf-engine: xelatex
|
||||
papersize: a4
|
||||
documentclass: scrreprt
|
||||
@ -120,6 +122,7 @@ execute:
|
||||
eval: true
|
||||
freeze: auto
|
||||
daemon: 3600
|
||||
preserve-ansi: true
|
||||
|
||||
keep-ipynb: true
|
||||
keep-tex: true
|
||||
|
414
chapters/13_IO.qmd
Normal file
414
chapters/13_IO.qmd
Normal file
@ -0,0 +1,414 @@
|
||||
# Ein- und Ausgabe I/O
|
||||
|
||||
zahlreiche Varianten und Funktionen, das Folgende ist eine kleine Auswahl
|
||||
|
||||
## Konsole
|
||||
|
||||
- OS-abhängig; üblicherweise 3 Kanäle _(streams)_: `stdin, stdout, stderr` (Standardinput, -output, -errorkanal)
|
||||
|
||||
|
||||
|
||||
- Schreiben nach `stdout`: `print()`,`println()`,`printstyled()`
|
||||
- Schreiben nach `stderr`: `print(strerr,...)`, `println(stderr,...)`, `printstyled(stderr,...)`
|
||||
- Lesen von `stdin`: `readline()`
|
||||
|
||||
### Umwandeln von Strings in andere Typen:
|
||||
|
||||
- `chomp()` entfernt newline
|
||||
- `split()` zerlegt in "Wörter"
|
||||
- `parse()` wandelt in andere Typen um
|
||||
|
||||
### Buffer
|
||||
|
||||
- `write`-Zugriffe werden gebuffert.
|
||||
|
||||
- `flush(stdout)` leert Buffer
|
||||
|
||||
|
||||
```julia
|
||||
# aus dem ersten Beispielprogramm
|
||||
|
||||
function input(prompt = "Eingabe:")
|
||||
println(prompt)
|
||||
flush(stdout)
|
||||
return chomp(readline())
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
a = input("Bitte 2 Zahlen eingeben!")
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
av = split(a)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
parse.(Int, av)
|
||||
```
|
||||
|
||||
|
||||
```{julia}
|
||||
# Ausgaben auf den Fehlerkanal stderr erscheinen im Jupyter in rot:
|
||||
@warn "Das @warn-Macro schreibt nach stderr."
|
||||
println("Hallo!")
|
||||
println(stderr, "Das sollte nicht passieren!")
|
||||
```
|
||||
|
||||
### Einzelne Tastenanschläge einlesen
|
||||
|
||||
- `readline()` u.ä. warten auf den Abschluss der Eingabe durch Drücken der `Enter`-Taste.
|
||||
- Zum Einlesen einzelner _keystrokes_:
|
||||
|
||||
- [https://stackoverflow.com/questions/56888266/how-to-read-keyboard-inputs-at-every-keystroke-in-julia](https://stackoverflow.com/questions/56888266/how-to-read-keyboard-inputs-at-every-keystroke-in-julia)
|
||||
- [https://stackoverflow.com/questions/60954235/how-can-i-test-whether-stdin-has-input-available-in-julia](https://stackoverflow.com/questions/60954235/how-can-i-test-whether-stdin-has-input-available-in-julia)
|
||||
|
||||
|
||||
## Formatierte Ausgabe mit dem `Printf`-Paket
|
||||
|
||||
Die Macros `@sprintf` und `@printf` sind den gleichnamigen C-Funktionen nachempfunden
|
||||
|
||||
- Formatstring: Normaler String mit Platzhaltern
|
||||
- Platzhalter haben die Form
|
||||
```
|
||||
%[flags][width][.precision]type
|
||||
```
|
||||
(wobei die Angaben in eckigen Klammern alle optional sind)
|
||||
- Typen:
|
||||
```
|
||||
%s string
|
||||
%i integer
|
||||
%o integer octal (base=8)
|
||||
%x, %X integer hexadecimal (base=16) with digits 0-9abcdef or 0-9ABCDEF, resp.
|
||||
%f floatong point number
|
||||
%e floating point number, scientific representation
|
||||
%g floating point, uses %f or %e depending on value
|
||||
```
|
||||
|
||||
- Flags:
|
||||
```
|
||||
Pluszeichen: rechtsbündig (Standard)
|
||||
Minuszeichen: linksbündig
|
||||
Null: mit führenden Nullen
|
||||
```
|
||||
|
||||
- Width:
|
||||
```
|
||||
Anzahl der minimal verwendeten Zeichen (wenn nötig, werden auch mehr genommen)
|
||||
```
|
||||
|
||||
|
||||
Zeit für Beispiele:
|
||||
|
||||
|
||||
```julia
|
||||
using Printf # Paket laden nicht vergessen!
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("|%s|", "Hallo") # string mit Platzhalter für String
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("|%10s|", "Hallo") # Minimallänge, rechtsbündig
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("|%-10s|", "Hallo") # linksbündig
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("|%3s|", "Hallo") # Längenangabe kann überschritten werden
|
||||
# besser eine 'kaputt formatierte' Tabelle als falsche Werte!!
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
j = 123
|
||||
k = 90019001
|
||||
l = 3342678
|
||||
|
||||
@printf("j= %012i, k= %-12i, l = %12i", j, k, l) # 0-Flag für führende Nullen
|
||||
```
|
||||
|
||||
`@printf` und `@sprintf` können wie alle Macros wie Funktionen aufgerufen werden:
|
||||
|
||||
|
||||
```julia
|
||||
@printf("%i %i", 22, j)
|
||||
```
|
||||
|
||||
-- oder wie Macros, also ohne Funktionsklammern und ohne Komma:
|
||||
|
||||
|
||||
```julia
|
||||
@printf "%i %i" 22 j
|
||||
```
|
||||
|
||||
`@printf` kann als erstes Argument noch einen stream übergeben bekommen.
|
||||
|
||||
Ansonsten besteht die Argumentliste aus
|
||||
|
||||
- Formatstring mit Platzhaltern
|
||||
- Variablen in der Reihenfolge der Platzhalter, in Anzahl und Typ zu den Platzhaltern passend
|
||||
|
||||
|
||||
```{julia}
|
||||
@printf(stderr, "Erstes Resultat: %i %s\nZweites Resultat %i",
|
||||
j, "(geschätzt)" ,k)
|
||||
```
|
||||
|
||||
`@sprintf` druckt nichts, sondern liefert den ausgefüllten formatierten String zurück:
|
||||
|
||||
|
||||
```julia
|
||||
str = @sprintf("x = %10.6f", π );
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
str
|
||||
```
|
||||
|
||||
##### Formatierung der Gleitkommazahlen:
|
||||
|
||||
Bedeutung des _Precision_-Wertes:
|
||||
|
||||
- `%f` und `%e`-Format: max. Anzahl der Nachkommastellen
|
||||
- `%g`-Format: max. Anzahl von ausgegebenen Ziffern (Vor- + Nachkommastellen)
|
||||
|
||||
|
||||
```julia
|
||||
x = 123456.7890123456
|
||||
|
||||
@printf("%20.4f %20.4e", x, x) # 4 Nachkommastellen
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("%20.7f %20.7e", x, x) # 7 Nachkommastellen
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf("%20.7g %20.4g", x, x) # insgesamt 7 bzw. 4 Stellen
|
||||
```
|
||||
|
||||
## Dateioperationen
|
||||
|
||||
Dateien werden
|
||||
|
||||
- geöffnet ==> Dabei ensteht ein neues _stream_-Objekt (zusätzlich zu `stdin, stdout, stderr`)
|
||||
- dann kann dieser _stream_ gelesen und geschrieben werden
|
||||
- geschlossen ==> _stream_-Objekt wird von Datei getrennt
|
||||
|
||||
```
|
||||
stream = open(path, mode)
|
||||
```
|
||||
|
||||
- path: Dateiname/pfad
|
||||
- mode:
|
||||
```
|
||||
"r" read, öffnet am Dateianfang
|
||||
"w" write, öffnet am Dateianfang (Datei wird neu angelegt oder überschrieben)
|
||||
"a" append, öffnet zum Weiterschreiben am Dateiende
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
f = open("datei.txt", "w")
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@printf(f, "%20i\n", k)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
println(f, " zweite Zeile")
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
close(f)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
;cat datei.txt
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
f = open("datei.txt", "r")
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
n = 0
|
||||
for i in readlines(f) # Lese zeilenweise
|
||||
n += 1
|
||||
println(n, i) # Drucke mit Zeilennummer
|
||||
end
|
||||
```
|
||||
|
||||
## Pakete für Dateiformate
|
||||
|
||||
Pakete für die Ein- und Ausgabe in den verschiedensten Dateiformaten
|
||||
|
||||
- [PrettyTables.jl](https://ronisbr.github.io/PrettyTables.jl/stable/) Ausgabe von formatierten Tabellen
|
||||
- [DelimitedFiles.jl](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/) Ein- und Ausgabe von Matrizen u.ä.
|
||||
- [CSV.jl](https://csv.juliadata.org/stable/) Ein- und Ausgabe von Dateien mit "comma-delimited values" u.ä.
|
||||
- [XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/tutorial/) Ein- und Ausgabe von Excel-Dateien
|
||||
|
||||
und viele andere mehr...
|
||||
|
||||
### Delimited Files
|
||||
|
||||
|
||||
|
||||
```julia
|
||||
using DelimitedFiles
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
A = rand(200,3)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
f = open("data2.txt", "w")
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
writedlm(f, A)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
close(f)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
;head data2.txt
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
B = readdlm("data2.txt")
|
||||
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
# man kann open() auch als 1.Argument eine function(iostream) übergeben, die auf den stream
|
||||
# angewendet wird, wonach der stream automatisch geschlosssen wird.
|
||||
#
|
||||
# Mit der do-Notation sieht obiger code so aus:
|
||||
|
||||
open("data2.txt", "w") do io
|
||||
writedlm(io, A)
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
### CSV und DataFrames
|
||||
|
||||
- [DataFrames.jl](https://dataframes.juliadata.org/stable/) ist ein Paket zum bequemen Umgang mit tabellarischen Daten
|
||||
|
||||
|
||||
|
||||
|
||||
```julia
|
||||
using CSV, DataFrames, Downloads
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
# Wetterdaten von Westerland, s. https://dev.meteostat.net/bulk/hourly.html
|
||||
|
||||
|
||||
url = "https://bulk.meteostat.net/v2/hourly/10018.csv.gz"
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
http_response = Downloads.download(url)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
file = CSV.File(http_response, header=false)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
# https://dev.meteostat.net/bulk/hourly.html#endpoints
|
||||
|
||||
# Spalte 1 Datum
|
||||
# 2 Uhrzeit (Stunde)
|
||||
# 3 Temp
|
||||
# 5 Luftfeuchtigkeit
|
||||
# 6 Niederschlag
|
||||
# 8 Windrichtung
|
||||
# 9 Windstärke
|
||||
|
||||
|
||||
df = DataFrame(file)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
describe(df)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
using StatsPlots
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
using Dates
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
# neue Spalte mit Sp.1 und 2 (date & time) kombiniert
|
||||
|
||||
df[!, :datetime] = DateTime.(df.Column1) .+ Hour.(df.Column2);
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
describe(df)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@df df plot(:datetime, :Column3)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
@df df plot(:datetime, [:Column9, :Column6, :Column3],
|
||||
xlims = (DateTime(2022,1,1), DateTime(2022,7,1)),
|
||||
layout=(3,1), title=["Wind" "Regen" "Temp"], legend=:none)
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
|
||||
```
|
@ -1,5 +1,8 @@
|
||||
# Container
|
||||
---
|
||||
engine: julia
|
||||
---
|
||||
|
||||
# Container
|
||||
|
||||
Julia bietet eine große Auswahl von Containertypen mit weitgehend ähnlichem Interface an.
|
||||
Wir stellen hier `Tuple`, `Range` und `Dict` vor, im nächsten Kapitel dann `Array`, `Vector` und `Matrix`.
|
||||
|
@ -1,18 +1,11 @@
|
||||
---
|
||||
format:
|
||||
html:
|
||||
include-in-header:
|
||||
text: |
|
||||
<script type="application/javascript">
|
||||
window.PlotlyConfig = {MathJaxConfig: 'local'}
|
||||
</script>
|
||||
engine: julia
|
||||
---
|
||||
|
||||
# Ein Beispiel zur Stabilität von Gleitkommaarithmetik
|
||||
|
||||
## Berechnung von $\pi$ nach Archimedes
|
||||
|
||||
```{julia}
|
||||
```julia
|
||||
#| error: false
|
||||
#| echo: false
|
||||
#| output: false
|
||||
@ -24,44 +17,25 @@ using Base64
|
||||
|
||||
## see https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/src/PlotlyJS.jl
|
||||
## https://discourse.julialang.org/t/encode-a-plot-to-base64/27765/3
|
||||
function IJulia.display_dict(p::PlotlyJS.SyncPlot)
|
||||
Dict(
|
||||
# "application/vnd.plotly.v1+json" => JSON.lower(p),
|
||||
# "text/plain" => sprint(show, "text/plain", p),
|
||||
"text/html" => let
|
||||
buf = IOBuffer()
|
||||
show(buf, MIME("text/html"), p)
|
||||
#close(buf)
|
||||
#String(resize!(buf.data, buf.size))
|
||||
String(take!(buf))
|
||||
end,
|
||||
"image/png" => let
|
||||
buf = IOBuffer()
|
||||
buf64 = Base64EncodePipe(buf)
|
||||
show(buf64, MIME("image/png"), p)
|
||||
close(buf64)
|
||||
#String(resize!(buf.data, buf.size))
|
||||
String(take!(buf))
|
||||
end,
|
||||
|
||||
)
|
||||
end
|
||||
|
||||
function Base.show(io::IO, mimetype::MIME"text/html", p::PlotlyJS.SyncPlot)
|
||||
uuid = string(UUIDs.uuid4())
|
||||
show(io,mimetype,@htl("""
|
||||
<div style="height: auto" id=\"$(uuid)\"></div>
|
||||
<script>
|
||||
require(['../js/plotly-latest.min.js'], function(plotly) {
|
||||
function Base.show(io::IO, mimetype::MIME"text/html", p::PlotlyJS.SyncPlot)
|
||||
uuid = string(UUIDs.uuid4())
|
||||
show(io,mimetype,@htl("""
|
||||
<div style="height: auto" id=\"$(uuid)\"></div>
|
||||
<script>
|
||||
require(['../js/plotly-latest.min.js'], function(plotly) {
|
||||
plotly.newPlot($(uuid),
|
||||
$(HypertextLiteral.JavaScript(json(p.plot.data))),
|
||||
$(HypertextLiteral.JavaScript(json(p.plot.layout))),{responsive: true});
|
||||
});
|
||||
</script>
|
||||
"""))
|
||||
"""))
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
## Berechnung von $\pi$ nach Archimedes
|
||||
|
||||
Eine untere Schranke für $2\pi$, den Umfang des Einheitskreises, erhält man durch die
|
||||
Summe der Seitenlängen eines dem Einheitskreis eingeschriebenen regelmäßigen $n$-Ecks.
|
||||
Die Abbildung links zeigt, wie man beginnend mit einem Viereck der Seitenlänge $s_4=\sqrt{2}$ die Eckenzahl iterativ verdoppelt.
|
||||
@ -165,8 +139,7 @@ layout = Layout(xaxis_title="Iterationsschritte", yaxis_title="rel. Fehler",
|
||||
plot([scatter(x=is, y=ϵ_A, mode="markers+lines", name="Iteration A", yscale=:log10),
|
||||
scatter(x=is, y=ϵ_B, mode="markers+lines", name="Iteration B", yscale=:log10)],
|
||||
layout)
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
---
|
||||
engine: julia
|
||||
---
|
||||
|
||||
# Maschinenzahlen
|
||||
|
||||
|
||||
|
||||
```{julia}
|
||||
for x ∈ ( 3, 3.3e4, Int16(20), Float32(3.3e4), UInt16(9) )
|
||||
@show x sizeof(x) typeof(x)
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
---
|
||||
engine: julia
|
||||
---
|
||||
|
||||
# Grundlagen der Syntax
|
||||
|
||||
@ -52,6 +54,7 @@ x = log(10)
|
||||
- Im interaktiven Betrieb (REPL oder Notebook) unterdrückt ein Semikolon nach der letzten Anweisung die Ausgabe des Ergebnisses dieser Anweisung.
|
||||
|
||||
:::{.callout-tip}
|
||||
|
||||
## Beispiel
|
||||
|
||||
Im interaktiven Betrieb wird der Wert der letzten Anweisung auch ohne explizites `print()` ausgegeben:
|
||||
|
14
index.qmd
14
index.qmd
@ -1,3 +1,6 @@
|
||||
---
|
||||
engine: julia
|
||||
---
|
||||
# Was ist Julia? {.unnumbered}
|
||||
|
||||
|
||||
@ -5,6 +8,16 @@ Julia ist eine noch recht junge für *scientific computing* konzipierte moderne
|
||||
|
||||
Ein kleines Codebeispiel:
|
||||
|
||||
```{julia}
|
||||
#| error: false
|
||||
#| echo: false
|
||||
#| output: false
|
||||
|
||||
using CairoMakie
|
||||
CairoMakie.activate!(type = "png")
|
||||
set_theme!(size=(800, 180))
|
||||
```
|
||||
|
||||
```{julia}
|
||||
using CairoMakie
|
||||
a = [3, 7, 5, 3]
|
||||
@ -20,7 +33,6 @@ end
|
||||
f
|
||||
```
|
||||
|
||||
|
||||
## Geschichte {.unnumbered}
|
||||
|
||||
- 2009 Beginn der Entwicklung am *Computer Science and Artificial
|
||||
|
Loading…
Reference in New Issue
Block a user