Commit d204be72 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

tutorial: lesson 1 InputNg

parent 367775b5
......@@ -17,8 +17,8 @@
\newcommand{\code}[1]{{\ttfamily #1}}
\rfoot{\thepage} %exit
......@@ -67,10 +67,57 @@ keywordstyle=\color{blue}\bfseries,frame=shadowbox}
Blah blah this is the intro here.
Why should you read this tutorial?
The motivation for this tutorial is that you can use PsimagLite in
your own C++ programs. Another reason to read this tutorial
is to learn C++. We will pose exercises from beginner to intermediate
to advanced. Moreover, some of the exercises will ask you to
add or modify or improve functionality in PsimagLite itself,
and so your solutions could be included in PsimagLite.
You are encouraged to git clone PsimagLite and make changes that
you think are suitable, and request pulls, and discuss in our
mailing list.
The actual topics to be discussed will become clear once we have
some lessons typed in. The actual .cpp programs that use and
illustrate how to use PsimagLite are going to be in
\cppFile{drivers/}. We'll try to make them fit in one page including
error testing, and additional pages of documentation in line.
The documentation inside the .cpp file will then be split
in parts, and each part will look like the following.
/* PSIDOC PartName
standard latex markup here
Note that the \texttt{PartName} will be something descriptive
of what we are talking about there and must be \emph{unique}.
Moreover, that part can be included in this document,
the \cppFile{tutorial.ptex} file, by using the command
\texttt{$\backslash$ptexPast\{PartName\}}, where you have to use
the right name for \texttt{PartName}.
This way we import documentation from each .cpp file
into this ptex file.
In addition to being sort, the .cpp files for the tutorial
should include compilation instructions without any \texttt{Makefile},
so that all includes and library paths and compiler switches
are visible in the command line. Dependencies must be kept
minimal; you'll need PsimagLite, of course, and a C++ compiler, but
other than that, we should really really try not to have dependencies
unless really needed.
What's an acceptable dependency?
If we are showing how to read an Ainur input then we need BOOST, but should
still compile without BOOST and run plain old data (POD) input files.
If we are showing how to integrate a function, then we need the GSL, but
again the example should be able to compile without it; it won't run
though, but display a message saying that the GSL is needed.
/* PSIDOC InputNg
blah blah blah
/* PSIDOC InputNg_Intro
\section{Lesson I: InputNg}
In this lesson we'll learn how to read a
properly formatted input file. This way when
you write your own C++ programs you'll have
an already available way to read parameters
from an input file and use them in your program.
You can go ahead an compile this example with
g++ testInputNg.cpp -I ../src/ -I.. -DUSE_BOOST -L ../lib -lpsimaglite -o testInputNg
Note that you need boost-dev or boost-devel and also you
must have lib/PsimagLite already compiled.
You can already go ahead an run it with the provided simple input
./testInputNg testInput.ain
What does this program do? It reads two or three ``labels'' from
testInput.ain and prints some of them to the terminal.
The labels have the form \texttt{label=value}, and we have
a scalar, a vector, and a string as examples.
So, now let's discuss the short program we have here.
First, note that we need two includes from PsimagLite.
PsimagLite files are usually under src, but in some
cases subdirectories are used. Here are the includes.
/* PSIDOC_CODE_START InputNg_Includes */
#include "InputNg.h"
#include "InputCheckBase.h"
class MyInputCheck : public PsimagLite::InputCheckBase {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment