\documentclass{beamer}
\mode<presentation>
{
%  \usetheme{AnnArbor}
%  \usetheme{Dresden}
%  \usetheme{Montpellier}
%  \usetheme{Antibes}
%  \usetheme{Frankfurt}
%  \usetheme{PaloAlto}
%  \usetheme{Bergen}
%  \usetheme{Goettingen}
%  \usetheme{Pittsburgh}	%!!
%  \usetheme{Berkeley}
%  \usetheme{Hannover}
%  \usetheme{Rochester}		%!!!
%  \usetheme{Berlin}
%  \usetheme{Ilmenau}
%  \usetheme{Singapore}
%  \usetheme{Boadilla}		%viel platz
%  \usetheme{JuanLesPins}
%  \usetheme{Szeged}		%!
%  \usetheme{boxes}
%  \usetheme{Luebeck}
%  \usetheme{Warsaw}
% \usetheme{Copenhagen}
  \usetheme{Madrid}
%  \usetheme{Darmstadt}
%  \usetheme{Malmoe}
%  \usetheme{default}
%  \usetheme{Marburg}

%  \setbeamercovered{transparent}
  % oder auch nicht

  %navigation aus, klaut nur platz
  %\setbeamertemplate{navigation symbols}{}
  \beamertemplatenavigationsymbolsempty  
}
\usepackage[latin1]{inputenc}
%\usepackage[german]{babel}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{natbib}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{subfigure}
% oder was auch immer

\usepackage[latin1]{inputenc}
% oder was auch immer

\usepackage{times}
\usepackage[T1]{fontenc}
% Oder was auch immer. Zu beachten ist, das Font und Encoding passen
% müssen. Falls T1 nicht funktioniert, kann man versuchen, die Zeile
% mit fontenc zu löschen.

\usepackage{listings} 

\lstset{
language=Matlab,                % choose the language of the code
tabsize=2,
frame=none, 
numbers=left, 
numberstyle=\tiny, 
numbersep=5pt,
stepnumber=2,
basicstyle=\tiny
}

\title[]% (optional, nur bei langen Titeln nötig)
{Beyond the Mouse -- A Short Course on Programming}

\subtitle
{2. Fundamental Programming Principles I:\\
Variables and Data Types
}

\author[Ronni Grapenthin]% (optional, nur bei vielen Autoren)
{Ronni Grapenthin}
\institute[UAF/GI] % (optional, aber oft nötig)
{
Geophysical Institute, University of Alaska Fairbanks
}

% - Namen müssen in derselben Reihenfolge wie im Papier erscheinen.
% - Der \inst{?} Befehl sollte nur verwendet werden, wenn die Autoren
%   unterschiedlichen Instituten angehören.

% - Der \inst{?} Befehl sollte nur verwendet werden, wenn die Autoren
%   unterschiedlichen Instituten angehören.
% - Keep it simple, niemand interessiert sich für die genau Adresse.

\date[\today] % (optional, sollte der abgekürzte Konferenzname sein)
{\today}
% - Vollee oder abgekürzter Name sind möglich.
% - Dieser Eintrag ist nicht für das Publikum gedacht (das weiß
%   nämlich, bei welcher Konferenz es ist), sondern für Leute, die die
%   Folien später lesen.

\AtBeginSection[]
{
  \frame{
    \frametitle{Today's schedule}
    \tableofcontents[currentsection,currentsubsection]
  }
}

% Falls Aufzählungen immer schrittweise gezeigt werden sollen, kann
% folgendes Kommando benutzt werden:

%\beamerdefaultoverlayspecification{<+->}

%\pgfdeclareimage[width=1.75cm,height=1.75cm]{logo_hu}{redoubt_images/pdc_cloud_2.pdf}
%\titlegraphic{\pgfuseimage{logo_hu}}

\setbeamertemplate{footline}[frame number]

\begin{document}

\frame{
	\begin{columns}[t]
	\column{0.5\textwidth}
		\titlepage
	\column{0.5\textwidth}
		\begin{center}
		\includegraphics[width=.75\textwidth]{images/xkcd_2009_04_14_well_2_panel_2.pdf}
		\end{center}
		\begin{flushright}
			\tiny{``The Uncomfortable Truths Well'',\\ http://xkcd.com/568 (April 13, 2009)}
		\end{flushright}
	\end{columns}
}

\frame{
  \frametitle{Today's schedule \dots}
  \tableofcontents
}

\section[Solutions]{Solutions to Exercises}
\frame{
	\frametitle{Exercise \#0}
		\begin{block}{\dots}
			thanks for the images :)
		\end{block}
}



\frame{
	\frametitle{Exercise \#1}
		\begin{center}
		\includegraphics<1>[width=9cm]{program_schedule/schedule.pdf}
		\includegraphics<2>[width=9cm]{program_schedule/schedule_fixing_01.pdf}
		\includegraphics<3>[width=9cm]{program_schedule/schedule_fixing_02.pdf}
		\includegraphics<4>[width=9cm]{program_schedule/schedule_fixing_03.pdf}
		\includegraphics<5>[width=9cm]{program_schedule/schedule_fixed.pdf}
		\end{center}
		\begin{flushright}
		{\tiny Listing 1: Seminar flow (fixed)}
		\end{flushright}
}

\frame{
	\frametitle{Exercise in general}
		\begin{center}
			I'll come back to you with individual comments on project snapshots, flow charts etc.
		\end{center}
}

\section[About Programming]{How does programming work?}
\frame{
	\frametitle{How does programming work?}
	\begin{center}
	Well, fist we should clearify terminology here!\\[20pt]
	What is a programming language?\\[20pt]
	What is a program?
	\end{center}
}

\frame{
	\frametitle{Alright, what is it then?}	
	\begin{block}{Definitions (broad sense)}
	A {\bf programming language} is an unambiguous artificial language that is made up of a set of symbols (vocabulary) and grammatical rules (syntax) 
	to instruct a machine. \\[20pt]
	A {\bf program} is a set of instructions in one or multiple programming languages that specifies the behavior of a machine.\\[20pt]
	{\bf Compilation} or {\bf interpretation} is the verification of a program and its translation into in the machine readable instructions of a specific platform.
	\end{block}
	
}

\frame{
	\frametitle{Programming languages \dots continued}	
	Two broad families can be identified:
	\begin{enumerate}
	\item<1-> {\bf Interpreted languages}\\
	An interpreter program is necessary to take in commands, check syntax and translate to machine language at runtime (e.g., Matlab, Unix Shell)
	\item<2-> {\bf Compiled languages}\\
	Programs are translated and saved in machine language. At runtime no additional program is necessary (e.g., C/C++).
	\end{enumerate}
%Note: show compiled language program vs interpreted script on shell ... i.e. less crusde, start matlab show something
}


\frame{
	\frametitle{Now, how does programming work?}
	\begin{enumerate}
	\item<2-> open {\bf text} editor (vi, notepad, \dots, not MS Word!)
		\begin{center}
		\includegraphics[width=7cm]{images/xkcd_real_programmers.png}~~{\tiny http://www.xkcd.com/378/}
		\end{center}
%		read {\tt http://en.wikipedia.org/wiki/Text\_editor} to get a better understanding.
	\item<3-> translate your (mental) flowchart into a set of instructions according to the rules of an applicable programming language 
	\item<4-> test your program for syntactical correctness (ask interpreter/compiler)
	\item<5-> if errors, fix them and go back to (3)
	\item<6-> test your program for semantical errors (the fun part!)
	\item<7-> if errors, fix them and go back to (3)
	\end{enumerate}
}

\frame{
	\frametitle{Don't even think that's as simple as it sounds \dots}
	\begin{block}{`Hello World' in Matlab}
		\begin{columns}[T]
		\column{0.75cm} ~
		\column{12cm}
		\lstinputlisting{./listings/02_fundamentals/hello_world.log}
		\end{columns}
		\begin{flushright}
		{\tiny Listing 2.1: hello\_world.log}
		\end{flushright}
	\end{block}
}


\section[Variables and Datatypes]{Variables and Datatypes}
\frame{
	\frametitle{Variables (1)}
	\begin{block}{Definitions -- a selection}
		{\bf Donald Knuth}: A quantity that may possess different values as a program is being executed.\\
		{\bf Mehran Sahami}: A box in which we stuff things -- i.e. a box with variable content.\\
		{\bf Wikipedia}: User defined keyword that is linked to a value stored in computer's {\bf memory} (runtime). 
	\end{block}

	The concept of a {\bf variable} consists of:
	\begin{itemize}
		\item <2-> name
		\item <2-> type
		\item <2-> value
	\end{itemize}
}

\frame{
	\frametitle{Memory interlude}
	\begin{center}
	\includegraphics<1>[width=.5\textwidth]{images/xkcd_485_depth_split01.png}
	\includegraphics<2>[width=.5\textwidth]{images/xkcd_485_depth_split02.png}
	\end{center}
	\begin{flushright}
		\tiny{``Depth'',\\ http://xkcd.com/485 (September 16, 2009)}
	\end{flushright}
}


\frame{
	\frametitle{Variables (2) -- name}
	\begin{itemize}
		\item<1-> USE MEANINGFUL NAMES!
		\item<2-> valid, follow programming language rules -- MATLAB variable names must {\bf begin with a letter}, followed by any {\bf combination of letters, digits, and underscores}. MATLAB distinguishes between uppercase and lowercase. \alert{No reserved keywords!}
		\item<3-> USE MEANINGFUL NAMES, i.e. names that speak:
		\item<4-> `{\tt lengthGlacier}' or `{\tt glacier\_length}' {\bf NOT NOT NOT} `{\tt a}' -- avoid ambiguity
		\item<5-> use consistent formatting, i.e.: `{\tt my\_cool\_var}' vs. `{\tt myCoolVar}' -- supports reading
		\item<6-> a gazillion style guides exist -- punchline: use meaningful names, be consistent (that's hard enough)!
	\end{itemize}

}

\frame{
	\frametitle{Variables (3) -- type}
	What is a type? -- Think of sets of numbers in math: $\mathbb{N}, \mathbb{R}, \mathbb{Z}$, \dots The type refers to how numbers are being 
	represented in a computer's memory, i.e. which bit has which meaning.\\
	\begin{block}{Two kinds of Types}<2->
	\begin{itemize}
		\item primitive, built in types -- for MATLAB e.g.: `{\tt int32}', `{\tt double}', `{\tt boolean}'
		\item complex, home made types -- (arrays,) structs, cell arrays (Matlab), classes/objects
	\end{itemize}
	\end{block}

	\begin{block}{Types in Programming Languages}<3->
	\begin{itemize}
		\item some languages, e.g. MATLAB, Shells, Perl are weakly typed: implicit type conversions (OR one type can be treated as another)
		\item this is nice at first, occasionally this leads to nasty/hard to fix problems (e.g. string interpreted as number, etc.)
	\end{itemize}
	\end{block}
}

\frame{
	\frametitle{Variables (4) -- value}
	\begin{block}{Value}
	\begin{itemize}
		\item a value of the type of the variable: {\tt 23, 3.1415926\dots, false}
		\item i.e., the thing we stuff in the box
		\item can/should change during the runtime of the program, otherwise use a constant (if possible)
	\end{itemize}
	\end{block}
	\begin{block}{Declaring a variable and Assigning a value:}<2->
	{\bf In General:} {\tt (type) name = value;} or {\tt (type) name = expression;} \\[10pt]
	{\bf Matlab:} {\tt myNewVar = 10;} {\bf TC-Shell} (differs) {\tt set myNewVar = 10;}\\
	Access to the values (de-referencing):\\
	{\bf Matlab:} use {\tt myNewVar;} {\bf TC-Shell} (differs) use `{\tt \$}': {\tt \$myNewVar}\\[10pt]	
	\end{block}
	\begin{block}{What's that?}<3->
	\begin{center}	
	{\tt myNewVar = myNewVar + 1;}
	\end{center}	
	\end{block}
}


\frame{
	\frametitle{Advanced Variables: Vectors and Matrices (1)}
	\begin{block}{Array variables}
	\begin{itemize}
		\item are lists, vectors, matrices of data (1 to n dimensional -- book keeping can become a hassle)
		\item therefore instead of one value they hold a {\bf list of values}
		\item linked to a chunk of memory (a sequence of boxes)
		\item access by index number
		\item MATLAB treats everything as a matrix. Shells allow only vectors.
	\end{itemize}
	\end{block}
}

\frame{
	\frametitle{Memory interlude (2)}
	\begin{center}
	\includegraphics<1>[width=.5\textwidth]{images/xkcd_485_depth_split03.png}
	\includegraphics<2>[width=.5\textwidth]{images/xkcd_485_depth_split04.png}
	\end{center}
	\begin{flushright}
		\tiny{``Depth'',\\ http://xkcd.com/485 (September 16, 2009)}
	\end{flushright}
}


\frame{
	\frametitle{Advanced Variables: Vectors and Matrices (2)}
	\begin{block}{Example}
	{\tiny
	\begin{tabular}{|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
		\hline
		index: & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 \\\hline
		sting: & h & e & l & l & o & ~ & w & o & r & l & d  & ! & ! & ! & ! \\\hline
		vector: & 12 & 23.3 & 23.3 & nan & nan & 1 & 42 & 42.1 & 23 & 5 & nan  & nan & 0 & 0 & 0 \\\hline
	\end{tabular}
	}
	\end{block}
}

\frame{
	\frametitle{Advanced Advanced Variables: {\tt struct} and Matlab {\tt cell array} (1)}

	\begin{block}{{\tt structs, cells}}
	\begin{itemize}
		\item organize and store data of different types in one variable
		\item these are containers you can put integers, doubles, strings, arrays of these, and other structs or cell arrays, etc ...
	\end{itemize}
	\end{block}

	\begin{block}{{\tt cell}}<2->
	\begin{columns}
 		\column{.55\textwidth}
			\begin{itemize}
				\item MATLAB specific data type, created using braces '\{...\}'
				\item must be used for strings of various length!
				\item elements are a vector in the memory -- access {\tt myCell(1)}, or {\tt myCell\{1,1\}}
				\item can contain any other data type
			\end{itemize}
 		\column{.45\textwidth}
			{\tiny
			\begin{tabular}{|l|l|l|}
				\hline
				{\tt myCell} & \{:,1\} & \{:,2\} \\\hline
				\{1,:\} & [1 5] & [2.4 3.6; 4.3 1] \\\hline
				\{2,:\} & \{'MacGyver' 'Bart'\} & true \\\hline
			\end{tabular}\\[10pt]
			}
			Access: {\tt myCell(1)}, {\tt myCell\{1,1\}} or as given in table.
	\end{columns}
	\end{block}
}

\frame{
	\frametitle{Advanced Advanced Variables: {\tt struct} and Matlab {\tt cell array} (2)}

	\begin{block}{{\tt struct}}
	\begin{columns}
 		\column{.5\textwidth}
			\begin{itemize}
				\item more organized array type: access to fields by a name
				\item can contain any other data type
				\item excellent for representing your tables of data
			\end{itemize}
 		\column{.5\textwidth}
			{\tiny
			\begin{tabular}{|l|l|l|l|}
				\hline
				{\tt student} & (1) & (2)& (3) \\\hline
				.name & 'Jack' & 'Jo' & 'Jake' \\\hline
				.age & 21 & 25 & 30 \\\hline
			\end{tabular}\\[10pt]
			}
			Access: {\tt student(1)}, {\tt student.age}, {\tt student.name}
	\end{columns}
	\end{block}
}

\end{document}
