source: Sophya/trunk/SophyaLib/Manual/piapp.tex@ 3442

Last change on this file since 3442 was 3442, checked in by ansari, 18 years ago

Ajout d'autres exemples d'expression plotting (sur francetopo.ppf) sur suggestion de cmv - Reza 15/12/2007

File size: 75.7 KB
Line 
1\documentclass[twoside,10pt]{article}
2% \usepackage[latin1]{inputenc}
3% \usepackage[T1]{fontenc}
4\usepackage[francais]{babel}
5\usepackage{graphicx}
6
7\usepackage{amsmath}
8\usepackage{amssymb}
9\usepackage{latexsym}
10
11\usepackage{palatino}
12
13% Definition pour Docs Sophya
14\usepackage{defsophya}
15
16\usepackage{makeidx}
17
18\usepackage[ps2pdf,bookmarks,bookmarksnumbered,%
19 urlcolor=blue,citecolor=blue,linkcolor=blue,%
20 pagecolor=blue,%hyperindex,%
21 colorlinks=true,hyperfigures=true,hyperindex=true
22 ]{hyperref}
23
24\setlength{\textwidth}{15cm}
25\setlength{\textheight}{20.5cm}
26\setlength{\topmargin}{0.cm}
27\setlength{\oddsidemargin}{0.cm}
28\setlength{\evensidemargin}{0.cm}
29\setlength{\unitlength}{1mm}
30
31% \newcommand{\piacommand}[1]{
32% \framebox{\bf \Large #1 } \index{#1} % (Command)
33%}
34% \newcommand{\piahelpitem}[1]{
35% \framebox{\bf \Large #1 } \index{#1} (Help item)
36%}
37
38\newcommand{\rond}{$\bullet \ $}
39\newcommand{\etoile}{$\star \ $}
40\newcommand{\cercle}{$\circ \ $}
41\newcommand{\carre}{$\Box \ $}
42
43%%%% Definition des commandes pour l'aide en ligne
44\newcommand{\piacommand}[1]{
45$\blacksquare$ \hspace{3mm} {\bf \Large #1 } \index{#1} % (Command)
46}
47\newcommand{\piahelpitem}[1]{
48$\square$ \hspace{3mm} {\bf \Large #1 } \index{#1} (Help item)
49}
50
51\newcommand{\menubar}[1]{\hspace{1mm} \framebox{\it MenuBar::#1} \hspace{1mm}}
52
53\newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
54
55\makeindex % Constitution d'index
56
57\begin{document}
58\begin{titlepage}
59% The title page - top of the page with the title of the paper
60\titrehp{piapp \\ An interactive data analysis tool}
61% Authors list
62\auteurs{
63R. Ansari & ansari@lal.in2p3.fr \\
64E. Aubourg & aubourg@hep.saclay.cea.fr \\
65C. Magneville & cmv@hep.saclay.cea.fr \\
66O. Perdereau & perderos@lal.in2p3.fr \\
67}
68% \author{R. Ansari {\tt ansari@lal.in2p3.fr} \\
69% E. Aubourg {\tt aubourg@hep.saclay.cea.fr} \\
70% C. Magneville {\tt cmv@hep.saclay.cea.fr}
71% }
72\vspace{1cm}
73\begin{center}
74{\bf \Large piapp Version: 4.1 (V\_Nov2007) }
75\end{center}
76\titrebp{5}
77
78\end{titlepage}
79
80\newpage
81\tableofcontents
82\newpage
83
84\section{Introduction}
85\index{piapp}
86{\bf piapp} (or {\bf spiapp}) is an interactive data analysis
87and visualization program. It is based on the {\bf PI} GUI library
88and the {\bf SOPHYA} \footnote{see http://www.sophya.org}
89(or {\bf PEIDA++} \footnote{PEIDA++ has been used in EROS software.
90(http://eros.in2p3.fr). It is not maintained anymore.})
91C++ data analysis class library.
92\par
93{\bf piapp} is a powerful command oriented tool for visualising and analysing data.
94Its main features are summarised below:
95\begin{itemize}
96\item[\rond] Image, multiple 2D and few 3D representations
97\item[\rond] Highly interactive graphics, with postscript as export format
98\item[\rond] Capability to handle large data sets. Data can be imported and
99exported in different formats: ASCII, PPF and FITS.
100\item[\rond] Interactive analysis: 2D/3D distributions, histograms, FFT \ldots
101\item[\rond] Flexible c-shell inspired command interpreter.
102\item[\rond] Possibility to perform more complex operations in C++, on objects
103managed by the application through the on-the-fly compilation and execution
104of c++ code fragments in piapp.
105\item[\rond] piapp is a multi-threaded program with separate threads for graphics
106and command execution, ensuring interactive response, even while heavy
107computation is being performed. In addition, thread safe commands can be executed
108in separate threads, for taking advantage of multi CPU (or CPU-cores) workstations.
109\item[\rond] The application can be easily extended through modules which can be
110loaded at run time.
111\end{itemize}
112
113\subsection{Acknowlegments}
114Many people have contributed to the development SOPHYA and/or the PI library
115and (s)piapp interactive analysis tool.
116we are grateful to the following people:
117
118\begin{tabular}{lcl}
119Reza Ansari & \hspace{5mm} & (LAL-Univ.Paris Sud, Orsay) \\
120Eric Aubourg & & (DAPNIA-CEA/APC, Saclay) \\
121Sophie Henrot-Versille & & (LAL-IN2P3/CNRS, Orsay) \\
122Alex Kim & & (LBL, Berkeley) \\
123Guy Le Meur & & (LAL-IN2P3/CNRS, Orsay) \\
124Eric Lesquoy & & (DAPNIA-CEA, Saclay) \\
125Christophe Magneville & & (DAPNIA-CEA, Saclay) \\
126Bruno Mansoux & & (LAL-IN2P3/CNRS, Orsay) \\
127Olivier Perdereau & & (LAL-IN2P3/CNRS, Orsay) \\
128Nicolas Regnault & & (LPNHE-IN2P3/CNRS, Paris) \\
129Benoit Revenu & & (APC/Univ.Paris 7, Paris) \\
130Francois Touze & & (LAL-IN2P3/CNRS, Orsay) \\
131\end{tabular}
132
133We thank also the persons who have helped us by useful suggestions, among others : \\
134S. Bargot, S. Plasczczynski, C. Renault and D. Yvon.
135
136%%%
137\begin{figure}[ht!]
138\begin{center}
139\includegraphics[width=15cm]{piapp_mainwin.eps}
140\caption{piapp main window}
141\label{figmainwin}
142\end{center}
143\end{figure}
144\subsection{starting piapp}
145 {\bf piapp} can simply be started on the command line in a terminal window
146once the SOPHYA/piapp environment has been initialised.
147The environment variables {\tt SOPHYABASE} should contain the directory
148where SOPHYA/piapp has been installed. the shared library path
149{\tt LD\_LIBRARY\_PATH} must contain {\tt \$SOPHYABASE /slb} and the
150current directory {\tt .} and the executable search path {\tt PATH} must
151contain {\tt \$SOPHYABASE /exe}. Refer to the SOPHYA overview manual
152for more information on SOPHYA directory structure. \\
153\par
154{\tt (s)piapp -h} provides a brief help of the command line
155arguments. Xtoolkit options can also be specified as command line
156arguments. {\bf spiapp} is the name of SOPHYA/piapp executable,
157in order to distinguish it from PEIDA/piapp.
158\begin{verbatim}
159csh> spiapp -h
160 SophyaInitiator::SophyaInitiator() BaseTools Init
161 PIOPersist::Initialize() Starting Sophya Persistence management service
162SOPHYA Version 2.1 Revision 0 (V_Nov2007) -- Nov 24 2007 13:08:58 gcc 3.3
16320030304 (Apple Computer, Inc. build 1495)
164 piapp: Interactive data analysis and visualisation program
165 Usage: piapp [-nored] [-doublered] [-termread] [-term]
166 [-hidezswin] [-small] [-nosig] [-nosigfpe] [-nosigsegv]
167 [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
168 -nored : Don't redirect stdout/stderr to piapp console
169 -doublered : Redirect stdout/stderr to piapp console AND the terminal
170 -termread : Read commands on terminal (stdin)
171 -term : equivalent to -nored -termread -small
172 -hidezswin : Hide Zoom/Stat/ColMap window
173 -small : Create small size main piapp window
174 -nosig : Don't catch SigFPE, SigSEGV
175 -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
176 -tmpdir TmpDirectory: defines TMDIR for temporary files
177 -help2tex: Create a LaTeX help file (piahelp.tex)
178 -exec file [args] : Execute command file (last option)
179\end{verbatim}
180Once {\bf piapp} is started, the main piapp window appears.
181It contains the menu bar, an upper part with the zoom and colormap
182widgets for image displays, memory and CPU usage and a terminal like
183widget (piapp console, see {\bf PIConsole} \myppageref{PIConsole})
184in the lower part. The figure \ref{figmainwin}
185shows an image of the piapp main window.
186{\tt stdout/cout, stderr/cerr} are redirected to the piapp console and
187commands can be entered in this widget. It is also possible to keep
188the terminal where piapp was started for {\tt stdout/stderr} (flag {\tt -nored}).
189The flag {\tt -term} activate a command reader on the terminal
190It is also possible to have a command reader on the terminal ({\tt stdin}). \\[1mm]
191
192\par
193In section 2, we present a quick tour of {\bf piapp}.
194a brief overview of piapp graphics, supported data formats, interactive
195analysis possibilities, the command interpreter and c++ execution
196are presented in the following sections.
197Section \ref{piappcmdref} contains a brief description of all piapp commands
198and help items. Various interactive control windows are described in appendix.
199
200\subsection{DemoPIApp and DemoData}
201The directory {\bf DemoPIApp} contains a number of example scripts, such as the
202{\tt demo.pic} and the associated data file {\tt demo.ppf}. It contains
203also examples of loadable modules for piapp. The DemoPIApp/CONTENT
204file contains a brief description of the different files. \\
205The {\bf DemoData} contains a number of data files, in PPF and FITS format, which are
206used for the examples in this document.
207
208\subsection{Warnings/Known problems}
209\begin{enumerate}
210\item It might be necessary to define the environment variable
211{\bf PIXKBMOMASK}, used by the libPI.a to map correctly
212the {\tt <Alt>} key with some X servers (in particular with
213X11 on MacOS X). \\
214{\tt csh> setenv PIXKBMODMASK 2 }
215However, the default value has been changed in PI/piapp V=4.1 and it should not be
216necessary anymore to define PIXKBMODMASK.
217%%
218\item The output redirection uses unix pipes. On Linux, with commands
219producing long outputs, the application may block because of incorrect management
220of pipes. If this happens, use piapp with {\tt -nored} flag. This problem has been
221in principle solved with SOPHYA V=2.1 / piapp V=4.1
222\end{enumerate}
223
224\newpage
225\section{A Tour of piapp}
226\subsection{Interacting with piapp, getting help}
227Users interact with piapp through commands entered in the piapp-console
228(or the unix terminal), and through the different menus.
229Some of the possibilities of the piapp-console are described
230in {\bf PIConsole} help item, in the command reference section \myppageref{PIConsole}.
231The description
232of the commands in available online using the help command.
233An online help window can be displayed by \menubar{File / Help}.
234Commands and help items are grouped in categories which can be
235selected using the OptionMenu in the Help window.
236\begin{verbatim}
237Cmd> help func
238Displays a function y=f(x) (Fills a vector with function values)
239 Usage: func f(x) xmin xmax [npt graphic_attributes]
240 Related commands: funcff func2d func2dff
241Cmd> func sin(x)/x 0.1 10 100 'red line=solid,2'
242---> Graphic display of the function
243\end{verbatim}
244The directory {\tt DemoPIApp} contains a number of example
245command script and sample data files.
246
247\subsection{The Object Manager (NamedObjMgr)}
248The {\bf piapp} application is built around an object manager
249(class {\tt NamedObjMgr}) and a graphic application
250(class {\tt PIStdImgApp}). Objects inheriting from
251the class {\tt AnyDataObj} can be managed through adapter
252classes (classes inheriting from {\tt NObjMgrAdapter}) by
253the object manager.
254\par
255User sees the objects (such as Sophya objects Histo, NTuple,
256Arrays, Images, SkyMaps, \ldots) kept in memory, organized
257in a single level tree structure. Four memory directories
258are automatically created and can not be removed: \\
259\centerline{\bf /home \hspace{10mm} /old \hspace{10mm} /tmp \hspace{10mm} /autoc}
260The default working directory (in memory) is {\bf /home}.
261Other directories can be created by the user.
262\begin{center}
263{\bf Warning:} These are only the directory
264structure managed by the piapp application and do not
265correspond to the file system directories
266\end{center}
267The window {\bf ObjMgr} shown in figure \ref{figobjmgrw}
268can be used to navigate in the memory directories and
269execute simple operations on objects. \\
270This window can be displayed using the menu command
271\menubar{Objects / ObjectManager}.
272The button \framebox{\small \bf SetCurObj} can be used to set the value
273of the interpreter's variable {\tt cobj} to the selected
274object name.
275Refer to the commands in group {\bf Object Management}
276for more information.
277
278\vspace*{5mm}
279\begin{figure}[ht!]
280\begin{center}
281\includegraphics[width=10cm]{piapp_objmgr.eps}
282\caption{The interactive object management window}
283\label{figobjmgrw}
284\end{center}
285\end{figure}
286
287\subsection{command language}
288A basic command interpreter ({\bf PIACmd/Commander}) is included in {\bf piapp} and
289other command interpreters can be inserted in the application
290framework.
291This interpreter ({\bf Commander} \myppageref{Commander})
292synthax is close to the c-shell
293(csh) shell script. It is possible to define and use variables
294({\tt set} command, {\tt \$varname}), and execute loops
295({\tt foreach,for}), as well as simple tests
296({\tt if test then ... else ... endif}).
297Commands from a file (default extension .pic) can be executed
298using the {\tt exec} command.
299Long commands can be put on several lines, by ending a line
300by the backslash \\ caracter, to signal that the command
301continues on the next line.
302
303The command macro below shows a sample piapp session, where
304data from the file {\tt demo.ppf} are displayed.
305\begin{verbatim}
306# Trace mode -> On
307traceon
308# Deleting all objects in the current directory
309delobjs *
310# Opening the PPF file demo.ppf
311openppf demo.ppf
312# Various displays in a graphic window, divided into 2x2 zones
313zone 2 2
314# 1D histogram display
315disp h1d blue
316# 2D histogram display
317disp h2d
318# Function display
319func sin(x)/x 0.1 10. 200 gold
320# Surface representation of a matrix
321surf mtx1 colbr32
322# Contour representation of a matrix
323contour mtx1 'colrj32 normalline ncont=7'
324# 3D representation of points using a PAW like command
325n/plot nt31.z%y%x ! ! win
326# 3D points superimposed on the previous display
327nt3d nt32 x y z ex ey ez - - 'same fcirclemarker7 red'
328\end{verbatim}
329
330\subsection{NTuple vue / PAW like commands}
331It is possible to plot various expressions of objects, seen as
332a 2D table, with named columns. This possibility exist not only
333for NTuples/DataTables, but also for most objects (from SOPHYA) handled
334by piapp. The related commands are grouped under {\bf Expr.Plotting} and
335{\bf pawCmd} and are described in section \ref{tableplot}.
336
337\subsection{C++ execution inside piapp}
338For more complex processings, where the full power of C++
339and the class libraries are necessary, {\bf piapp} provide
340the possibility of executing C++ code, without the burden
341of having to write a complete program. The objects
342present in the current directory are automatically
343declared. The communication with the piapp application
344is done by the {\bf NamedObjMgr} class.
345Two macros {\tt KeepObj()} and {\tt DisplayObj()}
346simplify the task of keeping newly created objects.
347In the example below, we first create a noisy signal
348in a vector, and we keep it in the application
349(Notice the use of multiline command) :
350
351\begin{verbatim}
352Cmd> c++exec c++exec Vector in(1024); \
353...? in = RandomSequence(RandomSequence::Gaussian, 0., 1.); \
354...? for(int kk=0; kk<in.Size(); kk++) \
355...? in(kk) += 2*sin(kk*0.05); \
356...? KeepObj(in);
357\end{verbatim}
358We can of course display the resulting vector:
359\begin{verbatim}
360Cmd> disp in
361\end{verbatim}
362
363And, at a subsequent stage, make a low pass filter
364on the vector in:
365\begin{verbatim}
366Cmd> c++exec Vector out(1024); \
367...? int w = 2; \
368...? for(int k=w; k<in.Size()-w; k++) \
369...? out(k) = in(Range(k-w, k+w)).Sum()/(2.*w+1.); \
370...? KeepObj(out);
371\end{verbatim}
372
373We can display the new vector {\tt out} overlayed
374on the previously displayed vector:
375\begin{verbatim}
376Cmd> disp out 'red same'
377\end{verbatim}
378
379See section \ref{flycplusplus} and command group {\bf CxxExecutorCmd}
380for more information.
381
382\subsection{Extending the application}
383The {\bf piapp} application can easily be extended by the user.
384This is done through shared libraries which can be opened
385and used by the application.
386Two main methods can be used (see command group
387{\bf ExternalModules}) :
388\begin{itemize}
389\item Creation of user functions. A shared library containing
390at least one user function with the following prototype
391should be created:
392\begin{verbatim}
393extern "C" {
394 void myfonction(vector<string>& args);
395}
396\end{verbatim}
397The class {\bf NameObjMgr} should be used to communicate with the
398application. The {\tt link} \myppageref{link} and {\tt call} \myppageref{call}
399should be used to load and execute user functions. An example of
400user function can be found in DemoPIApp/user.cc exlink.pic.
401
402\item Creation of loadable modules: Loadable modules can be
403used to extend the application possibilities in a way totally
404transparent to the user. It is possible to define new commands,
405handling of new object types, additional graphic functionalities
406in a loadable module.
407
408The class {\bf CmdExecutor} is the base class for extending piapp.
409A shared library should be built, containing two functions,for
410the activation and deactivation of the module, with the following
411prototype (where {\tt mymodule} is the module's name.
412\begin{verbatim}
413extern "C" {
414 void mymodule_init();
415 void mymodule_end();
416}
417\end{verbatim}
418
419\end{itemize}
420
421%%%%%%%%%% Section 3: Graphiques
422\newpage
423\section{Interactive graphics}
424\label{intgraphics}
425%%%
426\subsection{Display commands}
427Many objects managed by piapp have a default graphic representation. The
428{\bf disp} command \myppageref{disp} can be used to display the object, while
429other commands like {\bf surf} \myppageref{surf} , {\bf imag}
430or {\bf contour} \myppageref{contour} will try to force a given graphic representation.
431
432Data from table like objects can be plotted using commands like {\bf nt2d}
433\myppageref{nt2d} or {\bf nt3d} \myppageref{nt3d}. Most objects in piapp
434can also be manipulated like table for plotting purposes, using commands
435like {\bf plot2d} \myppageref{plot2d} , {\bf plot3d} \myppageref{plot3d}
436or {\bf n/plot} \myppageref{nZplot}. These commands are described in section
437\ref{tableplot}.
438
439Commands producing a graphic output have usually an optional argument called \\
440{\tt graphic\_attributes} or {\tt gr\_att}. \\
441This argument provide a flexible and easy
442way to change and customise the output graphic, as discussed in the paragraphs below.
443
444The piapp graphics can be exported in postscript (.ps) or encapsulated postscript
445(.eps) format. The commands {\bf w2ps} \myppageref{w2ps} and
446 {\bf w2eps} \myppageref{w2eps} as well the menu \menubar{PostScript} can
447 be used to export graphics. \\[2mm]
448The examples in the following pages illustrates the usage of some piapp graphic commands.
449% \newpage
450\begin{enumerate}
451\label{francetopo}
452\item Image display. The following example uses the data file francetopo.ppf
453which can be found in the {\bf DemoData} directory. This PPF file contains
454a TMatrix$<$int\_2$>$ (short integers) representing 30 arcmin gridded
455($\sim$ 1 km N-S $\times$ 0.7 km E-W) elevation (or altitude)
456for the area centered on France. It has been made using topographic
457data (DEM: Digital Elevation Model) available from the {\bf N}ational
458{\bf G}eophysical {\bf D}ata {\bf C}enter
459\href{http://www.ngdc.noaa.gov/mgg/topo/}{({\bf NGDC/GLOBE})}
460\footnote{NGDC web site: \hspace{5mm}
461http://www.ngdc.noaa.gov/ }.
462In section \ref{tableplot}, an example shows how to use this data set to
463create altitude distribution histogram for selected regions.
464\begin{verbatim}
465# Open a PPF file containing topographic data for france
466# as a TMatrix<short> 1332x1548
467# The file is in the directory DemoData/
468openppf francetopo.ppf
469# Display the matrix, whit a zoom factor, lut and color map
470disp francetopo 'zoom/3 lut=lin,-700,800 colbr128 win'
471w2eps francetopo.eps
472\end{verbatim}
473\begin{center}
474\includegraphics[width=13cm]{francetopo.eps}
475\end{center}
476
477\item Simple 2D graphics with vector displays
478\begin{verbatim}
479# Create and initialize two vectors - prevent display : nodisp
480Cmd> newvec vva 100 sin(x/10.+0.7)+cos(x/7.+1.4)*1.26 nodisp
481Cmd> newvec vvb 100 sin(x/10.)+cos(x/7.)*1.34 nodisp
482# Set axe drawing options
483Cmd> setaxesatt 'font=times,bold,16 minorticks tickslen=0.02,0.012'
484# Display the two vectors, with different graphic attributes
485Cmd> disp vva 'red line=solid,2 notitle'
486# Define a title for the graphic
487Cmd> settitle 'Example-1: 2 vectors' ' ' 'font=times,bolditalic,18'
488Cmd> disp vvb 'blue marker=box,7 same'
489# Save the graphic into an eps file
490Cmd> w2eps gr2vec.eps
491\end{verbatim}
492% \begin{figure}[ht!]
493\begin{center}
494\includegraphics[width=12cm]{gr2vec.eps}
495% \label{g22vec}
496\end{center}
497%%%
498\item Creating a comparison chart using {\bf bargraph}
499\begin{verbatim}
500# Representation du PNB (en $, 2003) pour quelques pays
501set pays ( Allemagne Espagne France Italie Pays-Bas Suisse UK USA )
502set pnbh ( 22670 14430 22010 18960 23960 37930 25250 35060 )
503setaxesatt 'font=times,bold,16'
504bargraph pnbh pays - 'blue horizontalbars nofill packfrac=0.65 font=helvetica,bold,14'
505setaxelabels 'PNB / Hab , $ 2003' ' ' 'font=times,bold,16'
506w2eps pnbargraph.eps
507\end{verbatim}
508\begin{center}
509\includegraphics[width=12cm]{pnbbargraph.eps}
510\end{center}
511%%%
512\item Displaying a matrix as a surface
513\begin{verbatim}
514openppf demo.ppf mtx1
515setaxesatt 'font=time,bold,16'
516surf mtx1 'colbr128 line=solid,1 grey'
517w2eps surfcol.eps
518\end{verbatim}
519\begin{center}
520\includegraphics[width=13cm]{surfcol.eps}
521\end{center}
522
523\end{enumerate}
524
525%%%%%%%%%%
526\subsection{Graphic objects in piapp}
527The piapp graphics is handled by the {\bf PI} \footnote {http://www.sophya.org/PI} library,
528which provide a large variety of 2D representations,
529few 3D graphics and powerful image display. \\
530Currently, all graphic representations, except for image displays, are handled
531through {\bf PIDrawers} which are managed by a viewer. A viewer can
532manage several {\bf PIDrawers} objects which correspond then to a multilayer
533graphic display. The viewers are also responsible for managing user
534interactions. \\
535Image displays are handled through a specific viewer
536{\bf PIImage} which is also capable of managing PIDrawer objects
537for multi-layer 2D overlay vector graphics. \\[2mm]
538%%
539Main piapp/PI graphic viewers, windows and drawer objects are described if
540the following sections.
541
542\subsubsection{PIScDrawWdg (2D display)}
543The {\bf PIScDrawWdg} handles a set of of 2-D drawers, managing
544the 2D coordinate system and interactive zoom. The axes drawing is
545handled by a specialised drawer, number 0, which also manages various added
546graphic elements (text \ldots). The list of various mouse and
547keyboard actions is described in the reference section, under {\bf PIScDrawWdg} \myppageref{PIScDrawWdg} title. In particular, mouse-button-2 can be used
548to zoom on a particular part, {\tt $<$Alt$>$A} activates the coordinates
549and axes manipulation window ({\bf PIAxesTools}) and {\tt $<$Alt$>$G}
550activates the PIDrawer graphic attributes control window ({\bf PIDrawerTools}).
551%%%
552\subsubsection{PIDraw3DWdg (3D display)}
553The {\bf PIDraw3DWdg} handles a set of of 3-D drawers, managing
554interactive camera/object rotation (mouse-button-2) and zoom (mouse-button-2).
555{\tt $<$Alt$>$G} to display/activate the PIDrawer graphic attributes
556control window ({\bf PIDrawerTools}).
557See {\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg} for a complete list of mouse
558and keyboard actions.
559Drawer 0 handles axes drawing and graphic elements.
560%%%
561\subsubsection{PIImage (Image Display)}
562The display of 2-D arrays $A(i,j)$ as an image is managed by
563the {\bf PIImage} viewer/widget. The PI library interface {\bf P2DArrayAdapter} is used
564to represent a generic 2-D array. The array values are converted into an index, converted
565itself into a color by the use of a color-map or color-table {\bf PIColorMap}.
566$$ \mathrm{LUT:} A(i,j) \longrightarrow idx(i,j) \hspace{5mm} \mathrm{ColorMap:}
567 idx(i,j) \longrightarrow col(i,j) $$
568Currently index range is 0...255 with color-map having 32 or 128 distinct colors.
569PIImage viewers controls a zoom widget, as well as a global image view widget, and
570a color map view widget. A specific image control window can be activated using
571 {\tt $<$Alt$>$O}. See {\bf PIImage} \myppageref{PIImage} for
572a complete list of mouse and keyboard actions. A base drawer (number 0) can handle
573axes drawing and added graphic elements.
574%%%
575\subsubsection{Windows}
576The viewers described above are displayed in differnt kind of windows.
577The graphic option {\tt next,win,same,stack} can be used to control the way the
578type of windows used. Graphic windows can be divided into several zones
579(Command {\bf zone} \myppageref{zone}).
580
581When an object is diplayed in piapp, a widget (PIWdg) is created which manages
582the drawer or the 2d-array. The default name for this widget is the displayed
583object name. However, it is possible to specify a name using the graphic attribute: \\
584\hspace*{5mm} {\tt wname=WidgetName} \\
585It is possible to display multiple objects on a single widget, corresponding
586to the superposition of the different drawers. Displaying an object superimposed
587on the previously displayed object can be done using the graphic option
588{\tt same}. It is also possible to specify a target widget by its name, through
589the graphic option \\
590\hspace*{5mm} {\tt samew=WidgetName} \\
591It is also possible to specify the display of the drawer in a specified region
592of the last displayed widget \\
593\hspace*{5mm} {\tt same=fx1,fx2,fy1,fy2} \\
594where {\tt fx1,fx2,fy1,fy2} express X and Y limits, as fraction of widget size.
595
596Refer to the command reference section on windows ({\bf Windows}
597\myppageref{Windows})
598for information on the different type of windows used by piapp
599and their properties. \\
600
601%%%
602\subsubsection{Drawers}
603Graphical representation of most objects in piapp is
604handled through objects inheriting from the {\bf PIDrawer class}. A base drawer
605(PIElDrawer, number 0) associated to all three above viewers manages the axes drawing
606as well as the added graphic elements (text, arrow, \ldots). A drawer management menu
607can be activated using {\tt $<$Alt$>$D}. This menu can be used to move and resize
608drawers, or to display a window for changing drawers graphic attributes.
609%%%
610\par
611In addition, a number of control windows can be used to examine and
612change view properties of differents viewers and drawers.
613\begin{itemize}
614\item[] {\bf PIDrawerTools} activated using {\tt $<$Alt$>$G} or
615\menubar{Tools/Show DrawerTools} on any viewer (see page \myppageref{secdrwtools})
616\item[] {\bf PIAxesTools} activated using {\tt $<$Alt$>$A} or
617\menubar{Tools/Show AxeTools} on PIScDrawWdg (see page \myppageref{secaxestools})
618\item[] {\bf PIImageTools} activated using {\tt $<$Alt$>$O} or
619\menubar{Tools/Show ImageTools} on PIImage
620(see page \myppageref{secimagetools})
621\item[] {\bf PIHisto2DTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
622for an active PIHisto2D drawer. (see page \myppageref{sech2dtools})
623\item[] {\bf PIContourTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
624for an active PIContourDrawer drawer. (see page \myppageref{secconttools})
625\end{itemize}
626These control tools are briefly described in appendix.
627
628%%%%%%%%%%
629\subsection{Graphic attributes}
630Graphic attributes are specified as a set of space separated strings. Use
631quotes to group them into a single argument parsed by the command
632interpreter. The options are decoded by the different objects handling the
633graphic (viewer widget, drawer, axe drawer). \\
634The complex decoding scheme
635is usually transparent for piapp users. However, there is an ambiguity when
636specifying some of the axes attributes, such as color or the font used for
637drawing the axes. The command {\bf setaxesatt} (\myppageref{setaxesatt})
638should thus be used to specify generic graphic attributes (color, font, line type). \\
639for axes.
640\begin{itemize}
641\item[\bul] The {\bf PIScDrawWdg} viewer options: \\
642\begin{verbatim}
643>> To define the 2D axes limits (in user coordinates)
644 xylimits=xmin,xmax,ymin,ymax
645>> To define the default drawing rectangle, in fraction of widget size
646 defdrrect=x1,x2,y1,y2 (default: x1=y1=0.1 x2=y2=0.9)
647>> Axes flags :
648 linx logx liny logy
649>> To change the background color (default=white)
650 wbgcol=colname
651
652\end{verbatim}
653%%%
654\item[\bul] The {\bf PIDraw3DWdg} viewer options: \\
655\begin{verbatim}
656>> To define the 3D box limits :
657 xyzlimits=xmin,xmax,ymin,ymax,zmin,zmax
658 limit3dbox=xmin,xmax,ymin,ymax,zmin,zmax
659>> Autoscaling flags (rescaling of X/Y or X/Y/Z axes)
660 autoscale3dbox / noautoscale3dbox
661 autoscalexy3dbox / noautoscalexy3dbox
662 autoscalez3dbox / noautoscalez3dbox
663>> To change the background color (default=white)
664 wbgcol=colname
665
666\end{verbatim}
667%%%
668\item[\bul] The {\bf PIImage} viewer options: \\
669\begin{verbatim}
670>> Define display zoomfactor
671 zoomxFact (zoomx2 zoomx3 ... zoomx9 ...)
672 zoom/Fact (zoom/2 zoom/3 ... )
673>> LUT (look-up table) definition (pixel value to index conversion)
674 lut=type,min,max (type=lin/log/sqrt/square)
675>> AutoLut selector : define the method for automatic determination
676 of LUT limits (min/max)
677 autolut=alt[,ns[,minp,maxp]] (minp<=pixels<=maxp)
678 - autolut=minmax[,Frac] 0<=Frac<=1
679 - autolut=meansig[,ns] --> mean +/- ns*sigma
680 - autolut=hispeak[,ns] --> around the peak of pixel values histogram
681 - autolut=histail[,ns] --> the tail of pixel values histogram
682>> Define color table and reversing color indexing flag
683 ColTableName revcmap
684 ==> Standard tables with 32 distinct colors:
685 grey32 invgrey32 colrj32 colbr32 colrv32
686 ==> Standard tables with 128 distinct colors:
687 grey128 invgrey128 colrj128 colbr128
688 ==> Shades of red/green/blue ...
689 red32cm green32cm blue32cm yellow32cm
690 orange32cm cyan32cm violet32cm
691 ==> Some of MIDAS color tables :
692 midas_pastel midas_heat midas_rainbow3
693 midas_bluered midas_bluewhite midas_stairs8
694 midas_stairs9 midas_staircase midas_color
695 midas_manycol midas_idl14 midas_idl15
696 ==> Other tables
697 multicol16 multicol64
698>> Viewed center position (image/array coordinates)
699 imagecenter=xc,yc
700>> Array axes to window axes mapping flags
701 invx invy exchxy
702>> To change the background color (default=black)
703 wbgcol=colname
704
705\end{verbatim}
706%%%
707\item[\bul] The {\bf PIGraphicAtt} Generic graphic attributes (color/font/line \ldots)
708decoded by all drawers: \\
709\begin{verbatim}
710>>> color=ColorName - fgcolor=ColorName - bgcolor=ColorName
711 ColorName: black white grey red blue green yellow
712 magenta cyan turquoise navyblue orange
713 siennared purple limegreen gold violet
714 violetred blueviolet darkviolet skyblue
715 royalblue forestgreen orangered brown
716>>> line=DashType,LineWidth
717 DashType: solid, dash, dotted, dashdotted Width: 1,2,...
718>>> font=FontName,FontAtt,FontSize
719 FontName: courier, helvetica, times, symbol
720 FontAtt: roman, bold, italic, bolditalic
721 FontSize: 6,8,10,12... (pts) - integer
722>>> marker=MarkerType,MarkerSize (MarkerSize: integer 3,5,7...
723 MarkerType: dot, plus, cross, circle, fcircle, box, fbox
724 triangle, ftriangle, star, fstar
725>>> arrow=ArrowType,ArrowSize (ArrowSize: integer 3,5,7...
726 ArrowType: basic, triangle, ftriangle,
727 arrowshaped, farrowshaped
728>>> ColorTables: defcmap grey32 invgrey32 colrj32 colbr32
729 grey128 invgrey128 colrj128 colbr128
730 red32cm green32cm blue32cm yellow32cm
731 orange32cm cyan32cm violet32cm
732 midas_pastel midas_heat midas_rainbow3 midas_bluered
733 midas_bluewhite midas_redwhite
734 multicol16 multicol64
735> revcmap : This flag reverses ColorMap indexing
736------- Old style graphic att ----------
737>> Lines: defline normalline thinline thickline dashedline thindashedline
738 thickdashedline dottedline thindottedline thickdottedline
739>> Font Att: deffontatt normalfont boldfont italicfont bolditalicfont
740 smallfont smallboldfont smallitalicfont smallbolditalicfont
741 bigfont bigboldfont bigitalicfont bigbolditalicfont
742 hugefont hugeboldfont hugeitalicfont hugebolditalicfont
743>> Font Names: deffont courierfont helveticafont timesfont symbolfont
744>> Marker: dotmarker<S> plusmarker<S> crossmarker<S> circlemarker <S>
745 fcirclemarker<S> boxmarker<S> fboxmarker<S> trianglemarker<S>
746 ftrianglemarker<S> starmarker<S> fstarmarker<S>
747 with <S> = 1 3 5 7 9 , Example fboxmarker5 , plusmarker9 ...
748
749\end{verbatim}
750%%%%
751\item[\bul] The {\bf PIElDrawer} decodes axe drawing attributes: \\
752\begin{verbatim}
753 >> Axe and grid configuration flags:
754 axesnone stdaxes defaxes
755 boxaxes boxaxesgrid fineaxes fineaxesgrid
756 centeredaxes finecenteredaxes centeredaxesgrid
757 finecenteredaxesgrid grid/nogrid
758 >> Centered axes position: axescenter=xc,yc
759 >> Axe ticks/labels (h=horizontal/x, v=vertical/y):
760 labels/nolabels hlabels/nohlabels vlabels/novlabels
761 ticks/noticks minorticks/nominorticks
762 extticks/intticks/extintticks nbticks=X_NbTicks,Y_NbTicks
763 tickslen=MajorTickLenFrac,MinorTickLenFraC
764 >> Axe label font size:
765 autofontsize=FontSizeFrac fixedfontsize
766 >> Up/Down title: title tit notitle notit
767 ... Color/Font/line attributes :
768
769\end{verbatim}
770\item[\bul] The {\bf PINTuple} handles most 2D plotting : \\
771\begin{verbatim}
772 sta,stat,stats: activate statistic display
773 nsta,nstat,nostat,nostats: deactivate statistic display
774 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
775 as a fraction of total size
776 connectpoints: The points are connected by a line
777 noconnectpoints (this is the default)
778 colorscale/nocolorscale (Use color scale for weight)
779 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
780 (and usual color/line/marker/... attribute decoding)
781
782\end{verbatim}
783%%%
784\item[\bul] {\bf PIHisto} and {\bf PIHisto2D} handle1D and 2D histograms display. \\
785The following options are recognised by PIHisto: \\
786\begin{verbatim}
787 ---- PIHisto options help info :
788 sta,stat,stats: activate statistic display
789 nsta,nstat,nostat,nostats: deactivate statistic display
790 err / noerr,nerr : draw, do not draw error bars
791 autoerr : draw error bars if Marker drawing requested OR Profile histo
792 fill / nofill,nfill : fill, do not fill bars with selected color
793 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
794 as a fraction of total size
795 ---- HistoWrapper options :
796 hbincont: select bin content as Y value for display (default)
797 hbinerr: select bin error as Y value for display
798 hbinent: select bin entries as Y value for display
799 hscale=value : multiplicative factor for Y value
800 hoffset=value : additive coefficient for Y value
801 hs1: set hscale=1 hoffset=0 (default)
802 hscale=value : multiplicative factor (in Y)
803
804\end{verbatim}
805The following options are recognised by PIHisto2D: \\
806\begin{verbatim}
807- sta,stat,stats: activate statistic display
808 nsta,nstat,nostat,nostats: deactivate statistic display
809- h2disp=typ[,fracpts]: choose display type
810 typ=var: variable size boxes
811 typ=hbk: "a la hbook2"
812 typ=img: image like (use "h2col" for color map)
813 typ=pts: point clouds (fracpts=max possible fraction
814 of used pixels per bin [0,1])
815- h2scale=lin/log[,logscale]: choose linear or logarithmic scale
816- h2dyn=[hmin][,hmax]: choose histogramme range for display
817- use general key to define color table (ex: grey32,midas_heat,...)
818 (see general graphicatt description)
819- use key "revcmap" to reverse color table
820- h2frac=[fmin][,fmax]: choose sub-range display [0,1]
821 ---- HistoWrapper options : (see HistoWrapper above)
822
823\end{verbatim}
824%%%%
825\item[\bul] The {\bf PINTuple3D} and {\bf PISurfaceDrawer}
826handles basic 3D plotting and can decode the common 3D box options: \\
827\begin{verbatim}
828 X/Y,Z axis rescaling option (-> cubic 3D box)
829 rescale=autoscale/ norescale=noautoscale : X/Y and Z axis
830 rescalexy=autoscalexy / norescalexy=noautoscalexy : X/Y axis
831 rescalexy=autoscalexy / norescalexy=noautoscalexy : Z axis
832\end{verbatim}
833The PINTuple3D decodes in addition the following options:
834\begin{verbatim}
835 connectpoints: The points are connected by a line
836 noconnectpoints (this is the default)
837 colorscale/nocolorscale (Use color scale for weight)
838 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
839
840\end{verbatim}
841\item[\bul] The {\bf (PIContourDrawer)} decodes the following options : \\
842\begin{verbatim}
843 autolevels : automatic selection of levels and number of contours
844 ncont=nLevel (or nc=NLevel) : sets the number of contour
845 lev=v1,v2,v3... (or niv=v1,v2,v3...) set the number and levels of contours
846 lstep=nLev,start,step : define incremental levels
847 labon/laboff : display of contour level values on/off
848 linear/bspline/cubicspl=3spl : select contour kind
849
850\end{verbatim}
851
852\item[\bul] {\bf PIBarGraph} options : \\
853\begin{verbatim}
854 ---- PIBarGraph options help info :
855 fill/nofill: set bar fill option
856 horizontalbars/verticalbars: set bar orientation
857 packfrac=value : set bar packing fraction (0..1)
858 barvaluelabel/nobarvaluelabel: Use/Don't use bar value as labels
859 --- + Usual colr/line/font attribute decoding ...
860 \end{verbatim}
861\end{itemize}
862
863
864%%%%%%%%%%%%%%% Section 4 : I/O
865\newpage
866\section{Data formats and input-output (I/O)}
867The data file formats recognized by piapp are the ones supported by the
868SOPHYA library or its extension.
869\begin{itemize}
870\item[\bul] ASCII files - Data can be imported from ascii (text) files as
871datatables or arrays. These objects can also be exported as text files.
872\item[\bul] FITS files - FITS is a popular format used in particular in astronomy.
873\href{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
874Data is usually read from FITS files as vectors, images, cubes or tables.
875A subset of SOPHYA objects can be imported or exported in FITS format.
876\item[\bul] PPF (Portable Persistence file Format) is the native SOPHYA
877data format.
878\item[\bul] PostScript - All graphic output produced by piapp can be exported
879as postscript (.ps) or encapsulated postscript (.eps) files.
880\end{itemize}
881
882\subsection{Text files}
883Text (or ascii) files can be read into array or datatable objects by spiapp.
884
885{\bf Arrays :} \\
886Arrays can be written to to files in text/ascii format using the {\tt arrtoascii}
887 \myppageref{arrtoascii} command. Double precision matrices and vectors
888 can be read from text files using the commands
889 {\tt mtxfrascii} \myppageref{mtxfrascii} and
890 {\tt vecfrascii} \myppageref{vecfrascii} . \\
891The menu-bar command \menubar{File/Open-ASCII} reads in a text
892file as a matrix.
893\begin{verbatim}
894# Create and initialize a matrix
895newmtx arr 250 150 x+3*y
896# Save the file in the text file arr.txt
897arrtoascii arr arr.txt
898# Read the previously created file and fill a matrix
899mtxfrascii mxa arr.txt
900# Print and display the matrix
901print mxa
902disp mxa zoomx2
903\end{verbatim}
904It is possible to specify the field separator in the input file, as well as the marker for the comment
905lines.
906
907{\bf DataTable :} \\
908Text files can also be read as a 2-D table (NTuple or DataTable). The table should be
909created using the {\tt newnt} \myppageref{newnt} or
910{\tt newdt} \myppageref{newdt} command.
911The command {\tt ntfrascii} \myppageref{ntfrascii} can then be used to append
912data from the file to the datatable.
913
914\subsection{PPF}
915%%%
916PPF (Portable Persistence file Format) is the the native persistence
917format of SOPHYA and thus is fully handled by spiapp. PPF files can
918be opened through the menu-bar \menubar{File/Open-PPF}, or through
919the {\tt openppf} \myppageref{openppf}.
920
921If the PPF file contains NameTags, only the objects marked with nametags are read and given
922the corresponding names. Otherwise, all objects are red sequentially, with their names
923formed by the filename followed by a sequence number. It is also possible to force the sequential
924reading specifying the {\tt -s} flag for openppf.
925
926The objects managed in spiapp by the {\bf NamedObjMgr} can be saved to PPF files, with their
927names as NameTags. The commands {\tt saveppf} \myppageref{saveppf} or
928 {\tt saveall} \myppageref{saveall} can be used to this end.
929
930\begin{verbatim}
931# Create two vectors and two matrices
932newvec va1 150 sin(sqrt(x))
933newvec vb2 150 sin(sqrt(x))*sqrt(x*0.1)
934newmtx mxa 250 150 x+2.*y
935newmtx mxb 250 150 sin(sqrt(x))*cos(sqrt(y))
936# List of the objects in memory
937listobjs
938# Save the two vectors in the file vecab.ppf
939saveppf v* vecab.ppf
940# Save the two matrices in the file mxab.ppf
941saveppf m* mxab.ppf
942\end{verbatim}
943
944\subsection{FITS}
945FITS files may contain three types of data structures
946\begin{enumerate}
947\item Image or array data structure : {\tt IMAGE\_HDU}
948\item Binary table : {\tt BINARY\_TBL}
949\item ascii table : {\tt ASCII\_TBL}
950\end{enumerate}
951The {\bf FitsIOServer} module contain FitsHandler classes which
952can map many SOPHYA classes on FITS data structures.
953Generic {\tt IMAGE\_HDU} correspond to the SOPHYA \tcls{TArray}
954class, while {\tt BINARY\_TBL} or {\tt ASCII\_TBL} is mapped
955to NTuple or DataTable.
956
957FITS format files can be read through the menu command \menubar{File/Open-Fits},
958or using {\tt readfits/openfits} \myppageref{readfits} command.
959Objects can be exported to FITS using the {\tt writefits/savefits}
960\myppageref{writefits} command.
961
962\begin{verbatim}
963# Open the PPF file created by the commands above
964openppf vecab.ppf
965# Export the two vector objects to file vecab.fits
966# Note that the '!' forces c-fitsio to overwrite the file, if it exists
967writefits v?? !vecab.fits
968\end{verbatim}
969
970There are two commands useful
971when analyzing large catalogs (BINARY\_TBL) in FITS format, which avoid reading the whole
972table in memory. {\tt swfitstable}\myppageref{swfitstable} reads a specified HDU
973as a {\bf SwFitsDataTable} object which uses the FITS file as swap space.
974The {\tt fitsadapt}\myppageref{fitsadapt} can also be used for similar purposes.
975
976The following commands shows how to open a FITS file containing a synchrotron map
977of our galaxy. This file contains sky emission at 408 MHz,
978as brightness temperature, represented as a SOPHYA spherical map
979(SphereHEALPix$<$r\_4$>$) in \href{http://healpix.jpl.nasa.gov/}{\bf HEALPix}
980format \footnote{HEALPix home page: \hspace{5mm} http://healpix.jpl.nasa.gov/}.
981It has been made, by rebinning, from the Haslam 408 MHz
982all sky survey map, available from the NASA CMB data repository
983\href{http://lambda.gsfc.nasa.gov/}{\bf LAMBDA}
984\footnote{LAMBDA web site: \hspace{5mm} http://lambda.gsfc.nasa.gov/}.
985\label{syncmap}
986\begin{verbatim}
987# Open the fits file : the map is in HEALPix format
988readfits syncmap.fits
989# Create a window with the appropriate size
990newwin 1 1 800 400
991# Display the map, specifying the colormap
992disp syncmap 'lut=lin,2,50 midas_bluered'
993\end{verbatim}
994\begin{figure}[h]
995\begin{center}
996\includegraphics[width=15cm]{syncmap.eps}
997\caption{Synchron map of our Galaxy, displayed in Molleweide projection.
998The underlying SOPHYA object is a \tcls{SphereHEALPix} }
999\end{center}
1000\end{figure}
1001
1002\subsection{Graphic export in postscript}
1003%%
1004Postscript a page description language widely used for printing and
1005graphic output, developed by Adobe systems. Refer to
1006\href{http://www.adobe.com/products/postscript/}{Adobe/PostScript3}
1007for more detail.
1008
1009Piapp graphic output can be exported in postscript (level 2) or
1010encapsulated postscript format, preserving the full precision
1011of vector graphics.
1012Postscript (.ps) files my contain several pages, each vue or window
1013corresponding to one page and are suitable for direct printing.
1014An Encapsulated Postscript (.eps) file contains a single page,
1015corresponding to a window and is suitable for inclusion in
1016other document.
1017
1018Postscript file can easily be converted to other formats,
1019PDF or image formats (jpeg \ldots) using converters like
1020{\bf ps2pdf} or {\bf imagemagick}.
1021
1022The menu items under \menubar{PostScript} can be used to export
1023graphics in postscript. The default file name is {\tt pia.ps}
1024or {\tt pia1.eps} {\tt pia2.eps} \ldots
1025The following commands can also be used to create postscriot file
1026from the display in the current graphic window:
1027\begin{itemize}
1028\item {\tt w2ps} \myppageref{w2ps} to add the current graphic
1029output as a new page to the output postscript file.
1030The current output postscript file (default = w2ps.ps)
1031should be closed before being used. Exiting piapp closes automatically
1032all postscript files.
1033\item {\tt psclosefile} \myppageref{psclosefile} to close the current
1034output postscript file.
1035\item {\tt pssetfilename} \myppageref{pssetfilename} To define
1036the output postscript file name for the subsequent {\tt w2ps} commands.
1037\item {\tt w2eps} \myppageref{w2eps} to export the current
1038graphic display, in Encapsulated Postscript format to the specified file.
1039\begin{verbatim}
1040# Open the PPF file created by the commands above
1041openppf vecab.ppf
1042# Display one of the vectors
1043setaxesatt 'font=helvetica,bold,18 fixedfontsize'
1044disp va1 'blue marker=box,5'
1045# Export the graphic to file va1.eps
1046w2eps va1.eps
1047# The created file can be viewed using gv
1048\end{verbatim}
1049\end{itemize}
1050
1051%%%%%%%%%%%%%%% Section 5 : analyse a la paw
1052\newpage
1053\section{Tables and Expression Plotting}
1054\label{tableplot}
1055A powerful data analysis technic available in piapp is
10562D, 3D plot, and histogramming applied to arbitrary analytical
1057expression of table columns.
1058This analysis technic has been introduced by the popular
1059CERN \href{http://paw.web.cern.ch/paw/}{\bf PAW}
1060({\bf P}hysics {\bf A}nalysis {\bf Workstation})
1061\footnote{PAW home page : http://paw.web.cern.ch/paw/ } program
1062and the underlying HBOOK fortran library.
1063Compared to PAW, piapp extends in many respects this capability,
1064piapp offers in particular the possibility to manipulate many
1065objects as if they where a DataTable, or NTuple.
1066There are also additional 2D and 3D representations e.g.
1067{\tt plot2de} \myppageref{plot2de},
1068{\tt plot2dw} \myppageref{plot2dw},
1069{\tt plot2dc} \myppageref{plot2dc} and
1070{\tt plot3dw} \myppageref{plot3dw}.
1071
1072\subsection{How does it work ?}
1073
1074The Expression.Plotting commands in piapp operate on objects through the
1075{\bf NTupleInterface} class methods. Some classes like NTuple or BaseDataTable
1076inherit from NTupleInterface, while for the other classes, the corresponding
1077NObjMgrAdapter class exposes an object conforming to NTupleInterface through the
1078method : \\
1079\hspace*{5mm} {\tt NTupleInterface* NObjMgrAdapter::GetNTupleInterface()} \\
1080A C file (PIATmp\_xxx/expf\_pia\_dl.c) is created by piapp containing the
1081specified expressions, which should conform to the C-language syntax.
1082In addition to the functions in {\tt math.h} (sin, cos, log \ldots),
1083the following functions are defined by piapp and can be used:
1084\begin{itemize}
1085\item Flat random number generators: {\tt drand01() , drandpm1() }
1086\item Gaussian random number generator: {\tt GauRand() }
1087\item Angle conversion: {\tt deg2rad(double d), rad2deg(double r) }
1088\item $(\theta,\varphi)$ to Molleweide X,Y projection: \\
1089\hspace*{5mm}{\tt double tetphi2mollX(double theta, double phi)} \\
1090\hspace*{5mm}{\tt double tetphi2mollY(double theta)}
1091\item Longitude(0..360) deg., Latitude(-90..90) deg. conversion to Molleweide X,Y: \\
1092\hspace*{5mm}{\tt double longlat2mollX(double longit, double lat) } \\
1093\hspace*{5mm}{\tt double longlat2mollY(double lat) }
1094\end{itemize}
1095
1096The processing steps for an Expression.Plotting in piapp :
1097\begin{enumerate}
1098\item Creation of the C-file.
1099\item On the fly compilation of the generated file.
1100\item The resulting shared-object is loaded and linked with the application
1101\item Loop over the NTupleInterface object rows. The created function is called
1102with the data from each row
1103\item The return values are used to fill an histogram, or a matrix/vector or
1104another NTuple or to produce a 2D or 3D graphic display.
1105\end{enumerate}
1106
1107Although rather complex, the efficiency gain during processing data easily compensates
1108for the overhead of the compilation step.
1109
1110\subsection{Column/variable names}
1111
1112When working with real 2-D tables (NTuple, DataTable \ldots), the column names
1113are the name of the variables which can be used in the C-expressions.
1114There is an additional variable, called {\tt \_nl}, automatically
1115provided by piapp, corresponding the table row number, starting from 0.
1116
1117For the other objects in piapp, the variable names are listed below:
1118\begin{itemize}
1119\item[\rond] For 2D table objects {\bf (NTuple,DataTable,\ldots)}: ColumnNames,\_nl
1120\item[\rond] For FITS files opened through {\tt fitsadapt} command: FITSColumnNames,\_nl
1121\item[\rond] For {\bf Histo1D/HProf} objects : i,x,val,err,nb,\_nl
1122\item[\rond] For {\bf Histo2D} objects : i,j,x,y,val,err,\_nl
1123\item[\rond] For {\bf HistoErr} objects : i,x,val,err2,nb,\_nl
1124\item[\rond] For {\bf Histo2DErr} objects : i,j,x,y,val,err2,nb,\_nl
1125\item[\rond] For {\bf \tcls{TVector}, \tcls{TMatrix} , \tcls{Image} } objects : \\
1126 \hspace*{10mm} n,r,c,val,real,imag,mod,phas,\_nl
1127\item[\rond] For {\bf \tcls{TArray}} objects : n,x,y,z,t,u,val,real,imag,mod,phas,\_nl
1128\item[\rond] For {\bf GeneralFitData} objects : x0,ex0 x1,ex1 ... xn,exn y,ey ,ok,\_nl
1129\item[\rond] For {\bf \tcls{SphereHEALPix} , \tcls{SphereThetaPhi} , \tcls{SphereECP}
1130\tcls{LocalMap} } objects : \hspace{10mm} i,k,val,real,imag,mod,phas,teta,phi,\_nl
1131\end{itemize}
1132
1133%%%%%
1134\subsection{Examples}
1135The following examples illustrates the use of some Expression Plotting commands
1136(see the command groups {\bf Expr. Plotting} \myppageref{ExprZZPlotting} and
1137 {\bf pawCmd} \myppageref{pawCmd}).
1138The {\bf pawCmd} defines a number of operations with command name and syntax
1139similar to the CERN PAW program.
1140The graphic output from the examples below are shown in the figures
1141\ref{exhis2dpl} and \ref{uzcpos}.
1142\begin{enumerate}
1143\item 2D plot with error bars \\[1mm]
1144\begin{verbatim}
1145# Set the axes attibute (the font used for axes ...)
1146setaxesatt 'font=helvetica,bold,16 minorticks fixedfontsize'
1147# Open the file demo.ppf (in DemoPIApp)
1148openppf demo.ppf
1149print nt21
1150print nt22
1151# 2D plot directly from the NTuple columns (nt2d)
1152# nt2d DO NOT use a compiled c file
1153nt2d nt21 x y - - - - 'font=helvetica,bold,16'
1154# Overlay a plot with scaled error bars from nt22
1155plot2de nt22 x y ex*0.3 ey*0.5 1 \
1156 'same marker=box,7 red font=helvetica,bold,16 '
1157\end{verbatim}
1158\vspace*{4mm}
1159\item Compute the histogram of pixel values for a \tcls{SphreHEALPix}.
1160The data come from the synchrotron map (syncmap.fits), described page \pageref{syncmap}.
1161\begin{verbatim}
1162# Open the synchrotron map file (HEALPix format spherical map)
1163# The file can be found in directory DemoData/
1164readfits syncmap.fits
1165newwin 1 1 800 400
1166disp syncmap 'lut=lin,2,50 midas_bluered'
1167newwin 1 2
1168# Compute and display the pixel value histogram (brightness temperature)
1169n/plot syncmap.val val<200 ! ! 'font=helvetica,bold,16 notit'
1170settitle 'Sky brightness @ 408 MHz' ' ' 'font=helvetica,bold,16'
1171# display the pixel value histogram in the galactic plane
1172n/plot syncmap.val val<200&&(fabs(teta-M_PI/2)<0.025) ! ! 'red notit'
1173settitle '408 MHz - Galactic plane' ' ' 'font=helvetica,bold,16 red'
1174\end{verbatim}
1175\vspace*{4mm}
1176\item Sources (galaxies) distribution over the sky. The data used below (uzc.ppf)
1177has been extracted from the {\bf U}pdated {\bf Z}wicky {\bf C}atalog of Galaxies,
1178available from the Harvard-Smithsonian Center For Astrophysics
1179\href{http://tdc-www.harvard.edu/uzc/}{CfA/UZC web site}.
1180\footnote{CfA web site: \hspace{5mm} http://tdc-www.harvard.edu/uzc/} \\[1mm]
1181%%%
1182\begin{verbatim}
1183# Keep the synchrotron map
1184# Open the Updated Zwicky Catalog of galaxies (in DemoData)
1185openppf uzc.ppf
1186zone 1 2
1187# Draw a longitude-latitude grid in Molleweide projection
1188mollgrid 5 7 'axesnone black font=helvetica,roman,12 notit'
1189# Overlay the sources distribution from UZC, for bright objects (mag<14)
1190plot2d uzc longlat2mollX(ra*15,dec) longlat2mollY(dec) mag<14 \
1191 'same red marker=circle,5'
1192# Change the plot title
1193settitle 'RA-Dec in degrees UZC (Updated Zwicky Catalog)' ' ' \
1194 'font=helvetica,bold,16 red'
1195# Display the synchrotron map
1196disp syncmap 'lut=lin,2,40 grey128'
1197# Add the source distribution in Galactic coordinates
1198plot2d uzc longlat2mollX(glong,glat) longlat2mollY(glat) mag<14 \
1199 'same nsta red marker=circle,5'
1200\end{verbatim}
1201%%%%%%%%%%%%%%%%
1202%%%%%%%%%%%%%%%%
1203\item Analysis of elevation (altitude) data for france. We use the francetopo.ppf
1204data set described page \pageref{francetopo}.
1205\begin{verbatim}
1206# open and display the topographic data for france
1207openppf francetopo.ppf (in DemoData/ directory)
1208print francetoto
1209#--- TMatrix<s>(NRows=1332, NCols=1548) ND=2 SizeX*Y*...= 1548x1332 ---
1210disp francetopo 'zoom/2 imagecenter=750,700 lut=lin,-700,800 colbr128'
1211# Compute the altitude distribution
1212newh1d altf 0. 4000 100
1213projh1d altf francetopo val val>0.1
1214# Display the histogram overlayed on the topographic map
1215disp altf 'white line=solid,2 font=helvetica,bold,14 inset=0.1,0.6,0.45,0.9'
1216# Compute altitude distribution for the massif central (Auvergne)
1217newh1d altmc 0. 2000 100
1218# We select the region as a circle of radius 200, centered on x=c=970,y=r=920
1219set regcut (sqrt((c-970)*(c-970)+(r-920)*(r-920))<200)
1220projh1d altmc francetopo val (val>0.1)&&$regcut
1221# Create a new window and display the two histograms
1222newwin 1 2
1223setaxesatt 'font=helvetica,bold,16 fixedfontsize'
1224disp altf 'notit'
1225settitle 'Elevation (altitude) distribution over France' ' ' \
1226 'font=helvetica,bold,16'
1227disp altmc 'notit'
1228settitle 'Elevation (altitude) distribution over MassifCentral' ' ' \
1229 'font=helvetica,bold,16'
1230\end{verbatim}
1231\end{enumerate}
1232
1233\begin{figure}[hp]
1234\includegraphics[width=15cm]{exhis2dpl.eps}
1235\caption{
1236top: 2d plot example with error bars \hspace{5mm}
1237bottom: Histogram of pixel values from the synchrotron map
1238of our galaxy}
1239\label{exhis2dpl}
1240\end{figure}
1241
1242\begin{figure}[p]
1243\includegraphics[width=15cm]{uzcpos.eps}
1244\caption{UZC: Updated Zwicky Catalog. \hspace{5mm}
1245top: The galaxy position distribution in equatorial
1246$(\alpha, \delta)$ coordinates. \hspace{5mm}
1247bottom: Position distribution in Galactic coordinates, superimposed on
1248the synchrotron map.}
1249\label{uzcpos}
1250\end{figure}
1251
1252%%%%%%%%%%%%%%% Section 6 : command interpreter
1253\newpage
1254\section{Command interpreter}
1255piapp uses the class {\bf PIACmd} which extends slightly the
1256SOPHYA class {\bf Commander} as the command interpreter.
1257{\bf Commander} is a c-shell inspired, string oriented command
1258interpreter. Although it has many limitations compared to
1259c-shell, or Tcl , it provides some interesting possibilities:
1260\begin{itemize}
1261\item Extended arithmetic operations (c-like and RPN)
1262\item Simple and vector variables
1263\item Script definition
1264\item Command execution in separate threads
1265\item Dynamic Load
1266\end{itemize}
1267
1268We describe below the {\bf Commander} possibilities,
1269as well as the few {\bf PIACmd} extensions.
1270
1271\subsection{Variables}
1272The SOPHYA::Commander interpreter manages non typed set of variables.
1273Environment variables are also accessible through
1274the usual {\tt \$varenvname}, unless shadowed by a Commander
1275variable. All Commander variables are vector of strings, and are
1276extended as necessary. {\tt \$varname} is the string formed by all
1277the vector elements. Except when performing arithmetic operations,
1278variables are treated as strings.
1279\par
1280An application level set of variables is also managed
1281by Commander, through redefinition of \\
1282{\tt Commander::GetVarApp() / GetVarApp() \ldots } methods. \\
1283The {\bf PIACmd} in piapp redefines the {\tt GetVarApp() }
1284in order to provide an easy access to some of objects attributes or methods,
1285managed by {\bf NamedObjMgr} (See below).
1286
1287\subsubsection{Interpreter/Commander variables}
1288\begin{itemize}
1289\item[\rond] {\bf Definition and initialisation of variables }
1290\begin{verbatim}
1291# Notice that the set command has no = sign
1292Cmd> set sv StringValue
1293# Clearing/removing of a variable : unset or clearvar
1294Cmd> unset sv
1295
1296# Definition of a multi element variable (vector type)
1297# Notice that spaces before / after '(' and ')' are mandatory
1298Cmd> set vecv ( mot1 mot2 mot3 mot4 mot5 )
1299# Arithmetic expression : C language syntax - spaces
1300# before/after '=' are mandatory
1301Cmd> a = 2+3*sqrt(4)
1302# The '=' operator can also be used to initialize a variable with a string
1303Cmd> a = 'Bonjour Madame'
1304# A vector element can be specified in the left hand side
1305Cmd> vecv[2] = 'coucou'
1306# Or using an interpreter variable as index :
1307Cmd> i = 3
1308Cmd> vecv[i] = 'Ooohhh'
1309\end{verbatim}
1310
1311On the right hand side, the value of a variable should be accessed using
1312the \$ character. \\
1313A string can be parsed into words using {\tt var2words}
1314\begin{verbatim}
1315Cmd> var2words varname wordvarname [separateur]
1316\end{verbatim}
1317
1318\item[\rond] {\bf Accessing variable contents } \\
1319The \$ character is used to access the content of a variable {\tt \$varname} .
1320Substitution rules :
1321The {\tt \$xxx} is replaced by the value of variable xxx.
1322No substitution is performed for strings enclosed in simple quotes {\tt ' ... \$xxx '},
1323but substitution is done in strings enclosed in double quotes.
1324Parenthesis or brackets can be used to specify the variable name, inside a string
1325without white space: {\tt \${vname} } ou {\tt \$(vname)}.
1326\begin{verbatim}
1327Cmd> x = 'Hello'
1328Cmd> echo $x
1329# Size of a vector variable : $#vname
1330Cmd> set vx ( 111 2222 3333 444444 )
1331Cmd> echo $#vx
1332# Accessing vector elements
1333Cmd> echo $vx[0] $vx[1]
1334# or using an interpreter variable as index :
1335Cmd> i = 2
1336Cmd> echo $vx[i]
1337# Special syntax: $[vname] is replaced by the content
1338# of a variable whose name is $vname
1339Cmd> zzz = 'Commander'
1340Cmd> xxx = 'zzz'
1341Cmd> echo '---> $[xxx]= ' $[xxx]
1342---> $[xxx]= Commander
1343\end{verbatim}
1344
1345\par
1346\end{itemize}
1347
1348\subsubsection{Special variables}
1349\begin{itemize}
1350\item {\tt \$retval} ou {\tt \$retstr} : the string specified in the last {\bf return} statement
1351\item {\tt \$status} : Return code from the last executed command.
1352Arguments of scripts (see below) or file executed through {\bf exec} command.
1353\item {\tt \$\# } : number of arguments, except \$0
1354\item {\tt \$0} : Script or file name
1355\item {\tt \$1 \$2 \$3} .... : Arguments (for scripts and .pic files (exec))
1356\end{itemize}
1357
1358\subsubsection{Environment variables}
1359Environment variables can simply be accessed by {\tt \$varenvname}.
1360However, the environment variables have the lowest priority during substitution.
1361Interpreter's variables have the highest priority, followed
1362by the application level variables.
1363
1364\subsubsection{Objects/Application level variables}
1365For some classes managed by NamedObjMgr,
1366PIACmd provide acces to some of the attributes of the object by
1367{\tt \${objname.attname} }. This mechanism has been implemented in particular for
1368TArrays, TMatrix/TVector, Histograms, NTuples and DataTables.
1369In addition, when brackets are used ($\${vname}$), the priority level between interpreter variables
1370and application level variable is changed. If {\tt vname} exist at the application level,
1371{\tt \${vname} } is replaced by its value, even if an interpreter variable with the
1372same name has been defined.
1373\begin{itemize}
1374\item[\rond] Accessing object attributes
1375\begin{verbatim}
1376# -------- Example with a Vector
1377piapp[1] newvec va 12
1378piapp[2] echo $va
1379TVector<d>(12) (nr=12, nc=1)
1380# ------- An undefined attribute, such as ? might be
1381# used to get list of valid attributes
1382piapp[3] echo ${va.?}
1383TMatrix.Att: rank size/nelts nrow/nrows ncol/ncols sum sumsq norm min ...
1384# Compound names, in the form name.att must be inclosed in
1385# braces {name.att}
1386piapp[4] echo ${va.size}
138712
1388# -------- Example with an histogram
1389piapp[8] newh1d his 0. 20. 40
1390piapp[10] echo ${his.?}
1391Histo1D: nbin binw mean sigma over under nentries ndata
1392 xmin xmax vmin vmax imin imax
1393piapp[11] echo ${his.nbin}
139440
1395\end{verbatim}
1396
1397\item[\rond] Accessing object.Info() \\
1398For objects having an DVList Info() object (TArray/TVector/TMatrix , NTuple, DataTable, SwPPFDataTable, it is possible to access DVList members by the corresponding names : \\
1399\hspace*{10mm} {\tt \$\{objName.info.varName\} }
1400\item[\rond] Getting DataTable rows \\
1401For NTuple and BaseDataTable objects (DataTable, SwPPFDataTable, SwFitsDataTable), it is
1402possible to get a string representation of a given row, by specifying
1403\$\{tableName.row\} followed by the row number (starting from 0) : \\
1404\hspace*{10mm} {\tt \$\{tableName.row.num\} }
1405\end{itemize}
1406
1407
1408
1409\subsection{Control structures}
1410
1411\begin{itemize}
1412\item[\rond] Enumerated loop:
1413\begin{verbatim}
1414foreach f ( w1 w2 w3 ... )
1415 ...
1416 echo $f
1417end
1418\end{verbatim}
1419
1420Note that spaces before/after '(' et and ')' are mandatory.
1421An alternative form uses a vector variable name :
1422\begin{verbatim}
1423foreach v vecname
1424 ...
1425 echo $v
1426end
1427\end{verbatim}
1428
1429\item[\rond] Integer type loop:
1430\begin{verbatim}
1431for i startInt:endInt[:stepInt]
1432 ....
1433 echo $i
1434end
1435\end{verbatim}
1436
1437\item[\rond] Integer type loop:
1438\begin{verbatim}
1439for f startFloat:endFloat[:stepFloat]
1440 ....
1441 echo $f
1442end
1443\end{verbatim}
1444
1445\item[\rond] Loop over lines of a file
1446\begin{verbatim}
1447forinfile line FileName
1448 ...
1449 echo $line
1450end
1451\end{verbatim}
1452
1453\item[\rond] The {\tt break} instruction can be used to exit from a loop
1454
1455\item[\rond] {\bf if then else} Conditional execution:
1456\begin{verbatim}
1457if ( test ) then
1458endif
1459
1460if ( test ) then
1461 ....
1462else
1463 ....
1464endif
1465\end{verbatim}
1466Note that spaces before/after '(' et and ')' are mandatory.
1467
1468test is in the form {\tt a == b} OR {\tt a != b} OR {\tt a < b} OR {\tt a > b}
1469OR {\tt a <= b} OR {\tt a >= b}. Comparison operators should be delimited
1470by spaces.
1471{\tt ==} et {\tt !=} make a string comparison, while
1472{\tt < , > , <= , >=} compare the values obtained after string to double conversion.
1473\end{itemize}
1474
1475\subsection{Script definition}
1476A script is a sequence of commands. It is very similar to the execution of commands
1477from a file ({\bf exec filename}). Once a script has been defined, it can be called specifying
1478specifying the script name followed by its arguments.
1479\begin{verbatim}
1480# Script definition :
1481defscript scriptname [description ]
1482 ....
1483endscript
1484
1485# Executing the script
1486Cmd> scriptname arg1 arg2 arg3 ....
1487\end{verbatim}
1488
1489The {\tt return} instruction stops the execution and returns from a script, or from a command
1490file called through {\bf exec}. \\
1491The commands {\bf listscript } and {\bf clearscript scriptname} can be used
1492to obtain the list of already defined script, or to clear a script definition.
1493
1494\subsection{Other built-in commands}
1495\begin{itemize}
1496\item[\rond] Instruction {\bf echo } to write the line to cout/stdout
1497\item[\rond] Instruction {\bf echo2file} to write (append) the line to file ({\tt echo2file filename ....})
1498\item[\rond] Instruction {\bf sleep nsec} wait for {\tt nsec} seconds
1499\item[\rond] Instructions {\bf timingon , timingoff , traceon , traceoff } \\
1500%
1501\item[\rond] {\bf exec filename [arg1 arg2 ... ] } to execute command from
1502the file named {\tt filename}. {\tt .pic} is the default extension for the interpreter
1503command files.
1504\item[\rond] {\bf help} and {help keyword/commandname }
1505\item[\rond] {\bf listvars , listcommands } to print the list of defined variables and known
1506commands
1507\item[\rond] An alias for a command by {\bf alias aliasname 'string ' }. Alias substitution
1508occurs for the first word in a command line. {\bf listalias} prints the list of all
1509defined aliases.
1510\item[\rond] Execution control (piapp/PIACmd extension):
1511It is possible to stop the interpreter execution in a loop, a script or
1512a command file by the {\bf stop} command, or using
1513 {\tt <Cntrl C>} in the piapp console (PIConsole) \\
1514\end{itemize}
1515
1516\subsection {Command execution in separate threads}
1517It is possible to create new threads to execute commands
1518( for non built-in interpreter commands). The syntax is similar
1519to unix shell background tasks: an {\&} should be added at the end
1520of the command line. A new thread is then created for the
1521execution of the command, if declared as thread safe \\
1522(see {\tt CmdExecutor::IsThreadable() }.
1523\par
1524Thread management commands:
1525\begin{itemize}
1526\item[\rond] {\bf thrlist }Print current list of threads, with the associated command
1527the thread identifier (integer ThrId) and its status.
1528\item[\rond] {\bf cleanthrlist } Removes all finished threads from the list.
1529An automatic cleanup is performed periodically.
1530\item[\rond] {\bf cancelthr ThId } / {\bf killthr ThId } Stops/kills the thread with
1531the identifier ThId. Avoid using theses commands as the cleanup does
1532not release some resources associated with
1533the thread (memory, mutex \ldots).
1534\end{itemize}
1535
1536Executing commands in a separate thread is useful for CPU or data intensive
1537commands. Most {\bf Expr.Plotting}
1538(plot2d, plot2dw, plot2de, plot3d, ntloop, fillvec, fillmtx \ldots)
1539and some of the {\bf pawCmd} (n/plot n/proj) are thread safe. However, due to the
1540current mutex lock management for these Expr.Plotting/pawCmd commands, only one
1541such command can run concurrently with other piapp threads.
1542Some of the commands in the {\bf CxxExecutorCmd} (
1543c++exec, c++execfrf, c++create, c++createfrf, c++compile, c++link) are also thread safe.
1544The same remark concerning lock management applies to these commands, while
1545CxxExecutorCmd commands can run in parallel with Expr.Plotting commands.
1546
1547
1548%%%%%%%%%%%%%%% Section 7 : c++ execution
1549\newpage
1550\section{On the fly C++ execution}
1551\label{flycplusplus}
1552Piapp operates on the underlying SOPHYA class library objects.
1553Obviously, only a small fraction of functionalities in the libraries
1554are directly available through the commands. On the fly C++ compilation
1555and execution in piapp provides an easy access to the whole class library.
1556
1557The {\bf NamedObjMgr} class handles most of the communication between different
1558component of the application, including user c++ code.
1559The NamedObjMgr class implements a singleton scheme, where all instances of the
1560class operate on the same data.
1561Most operations, in particular directory and object management are thread-safe.
1562The most usefull NamedObjMgr methods in user code are:
1563\begin{itemize}
1564\item Adding an object using its pointer. The object should be created using new. \\
1565{\tt \small bool NamedObjMgr::AddObj(AnyDataObj* obj, string \& nom, bool crd=false) }
1566\item Adding an object using its reference. The Object Adapter is used to Clone
1567the object. For classes like TArray or Spherical maps, implementing reference sharing,
1568the cloned object shares its data with the original object.
1569The Cloned object is then added to the list. \\
1570{\tt \small bool NamedObjMgr::AddObj(AnyDataObj\& obj, string \& nom, bool crd=false)}
1571\item Object display methods : \\
1572{\tt \small NamedObjMgr::DisplayObj(string \& nom, string dopt="") \\
1573NamedObjMgr::DisplayImage(string \& nom, \ldots ) \\
1574NamedObjMgr::DisplayNT(string \& nom, \ldots )} \\
1575\ldots
1576\item Access to other parts of the piapp application : \\
1577{\tt \small PIStdImgApp* NamedObjMgr::GetImgApp() \\
1578PIACmd* PIStdImgApp::CmdInterpreter() }
1579\end{itemize}
1580
1581\subsection{How does it work ?}
1582When one the {\bf CxxExecutorCmd} \myppageref{CxxExecutorCmd} commands
1583({\tt c++exec} or {\tt c++execfrf}) is invoked, piapp performs the
1584following operations:
1585\begin{itemize}
1586\item Create a c++ file, and includes the usual libstc++ and SOPHYA header files
1587(file named PIATmp\_xxx/cxx\_spiapp.cc)
1588\item The user code is put in a c++ function: \\
1589{\small \tt int usercxx( vector<string> \& args ) }
1590\item References to all objects present in the current working NamedObjMgr directory
1591(default=/home) are declared and initialized. Objects in the current directory can
1592thus be easily accessed through variables bearing the corresponding object name
1593in piapp.
1594\item The c++ source file is compiled and linked with SOPHYA libraries,
1595and any additional library, specified through {\tt c++mylibs} \myppageref{cZZmylibs}).
1596The compilation and link steps are carried by the SOPHYA class {\b CxxCompilerLinker}.
1597\item The resulting shared object is loaded by piapp and the function
1598{\tt usercxx()} is called.
1599\end{itemize}
1600
1601To facilitate communication with piapp/NamedObjMgr, two CPP macros are defined:
1602\begin{itemize}
1603\item[\rond] {\bf KeepObj(VarName) } where VarName is a user declared
1604c++ variable, corresponding to an object inheriting from AnyDataObj.
1605When this macro is called, the corresponding object is cloned by the object
1606Adapter and added to the list managed by NamedObjMgr,
1607with VarName as the object name.
1608\item[\rond] {\bf DisplayObj(VarName, graphic\_att) } adds the object and
1609request its display.
1610\end{itemize}
1611
1612\subsection{Examples}
1613
1614\begin{enumerate}
1615\item Computation using TimeStamp object. \\[1mm]
1616%%
1617$\longrightarrow$ File compdate.cc :
1618\begin{verbatim}
1619 TimeStamp now; // Current date
1620 TimeStamp y2000(2000,1,1,12,0,0.); // 1 jan 2000, 12:00
1621 cout << " Y2000=" << y2000 << " --> Now: " << now << endl;
1622 cout << " From Y2000 to Now= " << now.ToDays() - y2000.ToDays() << " days" << endl;
1623\end{verbatim}
1624$\longrightarrow$ piapp commands : \\
1625{\tt piapp> c++execfrf compdate.cc} \\
1626$\longrightarrow$ The result : \\
1627\begin{verbatim}
1628PIABaseExecutor: Call usercxx( ... )
1629 Y2000= 01/01/2000 12:00:0.0 UT --> Now: 13/12/2007 14:20:50.0 UT
1630 From Y2000 to Now= 2903.1 days
1631\end{verbatim}
1632%%%%
1633\item Working with objects in piapp: \\[1mm]
1634\begin{verbatim}
1635# We create three vectors
1636newvec va 256 sin(x/5.)
1637newvec vb 256 cos(x/18.)*exp(-x/150.)
1638newvec vc 256
1639# We call c++exec to make an operation on these vectors
1640c++exec vc=va+3.*vb;
1641# Display the resulting vector
1642disp vc
1643\end{verbatim}
1644%%%
1645\item Creating and adding new objects \\[1mm]
1646$\longrightarrow$ File myf\_fft.h :
1647\begin{verbatim}
1648inline double myf(double x)
1649{
1650return(3*sin(0.2*x)+4*cos(x)+5*sin(4*x+0.25)
1651 +3.5*cos(9*x+0.45) + 0.05*x);
1652}
1653\end{verbatim}
1654$\longrightarrow$ File myf\_fft.h :
1655\begin{verbatim}
1656TVector<r_8> in(4048);
1657TVector<r_8> noise(4048);
1658TVector< complex<r_8> > out;
1659in = RegularSequence(0., 0.05);
1660noise = RandomSequence(RandomSequence::Gaussian, 0., 4.);
1661MathArray<r_8> ma;
1662ma.ApplyFunctionInPlace(in, myf);
1663in += noise;
1664FFTPackServer FFTServ;
1665cout << " Calling FFT " << endl;
1666FFTServ.FFTForward(in, out);
1667DisplayObj(in, "");
1668DisplayObj(out, "red");
1669\end{verbatim}
1670$\longrightarrow$ piapp commands :
1671\begin{verbatim}
1672# Remove existing in/out objects
1673rm in out
1674# Divide then graphic window in two regions
1675zone 1 2
1676# Compile and execute the c++ code
1677c++execfrf fft.icc myf_fft.h
1678listobjs
1679\end{verbatim}
1680\end{enumerate}
1681
1682\subsection{Include files, libraries \ldots}
1683\begin{itemize}
1684\item[\rond] The different steps of c++exec or c++execfrf
1685can be performed by the following commands: {\tt c++create , c++createfrf,
1686c++compile, c++link, call}. This is useful when the same code
1687has to be executed multiple times.
1688\item[\rond] An interactive editing / c++ execution window can be
1689displayed through the menu-bar, \menubar{Tools/CxxExecutorWindow}
1690\item[\rond] The {\tt c++import} \myppageref{cZZimport}
1691activate inclusion of header files for additional SOPHYA modules,
1692such as Samba SkyMap SkyT FitsIOServe \ldots.
1693\item[\rond] The inclusion of additional header files and libraries
1694can be specified using the {\tt c++include} \myppageref{cZZinclude}
1695and {\tt c++mylibs} \myppageref{cZZmylibs}.
1696\item[\rond] A dialog window for changing various c++ compile and link
1697options can be displayed by through the menu-bar
1698\menubar{Special/CxxExecOption}
1699\end{itemize}
1700
1701
1702%%%%%%%%%%%%%%% Section 8 : command reference
1703\newpage
1704\section{piapp command reference}
1705\label{piappcmdref}
1706This section contains the description of piapp commands. This information
1707is available on-line, through the help command, or through a graphic
1708window, accessible by \menubar{File / Help}.
1709The help items and command are divided into different sections,
1710where related commands are grouped. \\[10mm]
1711
1712% \include{piahelp}
1713\input{piahelp.tex}
1714
1715% La partie des appendix
1716\appendix
1717\newpage
1718\section{Interactive control windows}
1719\subsection{DrawerTools} \index{DrawerTools}
1720\label{secdrwtools}
1721The {\bf PIDrawerTools}, shown in the figure \ref{figdrwtools} can be
1722used to change the graphic attributes (color, font, marker, \ldots)
1723of the Drawers displayed in 2D displays
1724({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}) or 3D displays
1725({\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg}), as well in image displays
1726{\bf PIImage} (\myppageref{PIImage}). The PIDrawerTools can be activated
1727either using {\tt Alt<G>} on a PIScDrawWdg,PIDraw3DWdg,PIImage,
1728or through the \menubar{Tools/Show DrawerTools}.
1729A given drawer can be selected through the DrawerId selector (+ / - buttons)
1730
1731\vspace*{5mm}
1732\begin{figure}[ht!]
1733\begin{center}
1734\includegraphics[width=8cm]{piapp_drwtools.eps}
1735\caption{PIDrawerTools}
1736\label{figdrwtools}
1737\end{center}
1738\end{figure}
1739%%%%
1740\subsection{AxesTools} \index{AxesTools}
1741\label{secaxestools}
1742The {\bf PIAxesTools}, shown in the figure \ref{figaxestools} can be used to
1743control and change the setting of axes on 2D displays
1744({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}).
1745The PIAxesTools can be activated
1746either using {\tt Alt<A>} on a PIScDrawWdg or through
1747the \menubar{Tools/Show AxesTools}.
1748
1749\vspace*{5mm}
1750\begin{figure}[ht!]
1751\begin{center}
1752\includegraphics[width=8cm]{piapp_axestools.eps}
1753\caption{PIAxesTools}
1754\label{figaxestools}
1755\end{center}
1756\end{figure}
1757%%%%%
1758\subsection{ImageTools} \index{ImageTools}
1759\label{secimagetools}
1760The {\bf PIImageTools}, shown in the figure \ref{figimgtools} can be used to
1761manipulate a display of type image. Image display are handled by the
1762{\bf PIImage} (\myppageref{PIImage}). The PIImageTools can be activated
1763either using {\tt Alt<O>} on a PIImage, or through the
1764\menubar{Tools/Show ImageTools}.
1765
1766\vspace*{5mm}
1767\begin{figure}[ht!]
1768\begin{center}
1769\includegraphics[width=8cm]{piapp_imgtools.eps}
1770\caption{PIImageTools}
1771\label{figimgtools}
1772\end{center}
1773\end{figure}
1774
1775\subsection{Histo2DTools} \index{Histo2DTools}
1776\label{sech2dtools}
1777The {\bf PIHisto2DTools}, shown in the figure \ref{figh2dtools} can be
1778used to control and change the display caracteristics of 2D histograms.
1779PIHisto2DTools can be activated
1780either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1781drawer is a PIHisto2DDrawer, or through the generic drawer tool
1782PIDrawerTools.
1783
1784\vspace*{5mm}
1785\begin{figure}[ht!]
1786\begin{center}
1787\includegraphics[width=8cm]{piapp_h2dtools.eps}
1788\caption{PIHisto2DTools}
1789\label{figh2dtools}
1790\end{center}
1791\end{figure}
1792
1793\subsection{ContourTools} \index{ContourTools}
1794\label{secconttools}
1795The {\bf PIContourTools}, shown in the figure \ref{figconttools} can be
1796used to control and change the caracteristics of contour displays.
1797PIContourTools can be activated
1798either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1799drawer is a PIContDrawer, or through the generic drawer tool
1800PIDrawerTools.
1801
1802\vspace*{10mm}
1803\begin{figure}[ht!]
1804\begin{center}
1805\includegraphics[width=11cm]{piapp_conttools.eps}
1806\caption{PIContourTools}
1807\label{figconttools}
1808\end{center}
1809\end{figure}
1810
1811
1812
1813Both drawing options (e.g. color, line type, fonts...) and contour
1814determination parameters (e.g. contour number and levels) are controlled
1815by {\bf PIContourTools}.
1816
1817\subsubsection{Drawing options}
1818The top choices in {\bf PIContourTools}
1819concern the color map (left choice) or color (right choice) of the contours.
1820If a color map has been chosen, it is used to give each contour a color
1821(according to its level). If no color map has been chosen, contours may be
1822given a color using the left choice box.
1823
1824Contour are by default traced by lines.
1825Alternatively (or in addition) the user may ask to trace them by markers
1826or to put numeric labels (with the contour's level) aside the contour.
1827These options are enabled/disabled by the {\tt LineON}, {\tt MarkerON} and {\tt LabelON}
1828buttons from {\bf PIContourTools}.
1829
1830Options may be recovered ({\tt GetAtt}) or set ({\tt SetAtt})
1831from/to a drawer. Setting an option which adds to the screen will be immediately visible
1832whereas unsetting it requires a {\tt Refresh} to be visible.
1833
1834
1835\subsubsection{Contour options}
1836The contouring routines in {\tt spiapp} are based on a hack of the {\tt GNUPlot}
1837routines. Contours are determined from a grid of values
1838using an interpolation scheme. Three schemes may be used
1839(selected by the left menu) :
1840\begin{enumerate}
1841\item Linear interpolation (default), selected by the {\tt Int. Lin.} option
1842\item A cubic spline algorithm, selected by the {\tt CubicSpl} option
1843\item A 2d BSpline algorihm, selected by the {\tt B-Spline} option
1844\end{enumerate}
1845
1846Contour levels and number are automatically
1847determined by the program. They may be specified differently,
1848 through command-line options
1849(see section \ref{piappcmdref} for the help of the contour/ntcont commands)
1850or the lower part of the {\bf PIContourTools} window.
1851
1852The user may specify one of the following alternatives :
1853\begin{enumerate}
1854\item the number of contour (their level beeing automatically set).
1855To do this, select {\tt LevelNum} in the right menu and enter the contour number
1856in the left box below.
1857\item the levels of the contours, through an array of numerical values
1858(e.g. 1,4,6,9,27,4.5 will result in 6 contour lines being drawn, if possible and necessary).
1859To do this, select {\tt LevelDisc} and enter the contour number (left box)
1860and the values (right box) separated by ``{\tt ,}''.
1861\item the levels of the contours through an initial (lower) value and an increment.
1862For this, select {\tt LevelInc} and enter the contour number (left box)
1863and the initial value and increment in the right box, as above.
1864\item come back to the default situation, by choosing {\tt LevelAuto}
1865\end{enumerate}
1866
1867Once these options are set, it is necessary the the program recomputes
1868the contour lines. This is commanded by the {\tt SetParm} button.
1869
1870
1871\newpage
1872\addcontentsline{toc}{section}{Index}
1873\printindex
1874
1875\end{document}
Note: See TracBrowser for help on using the repository browser.