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

Last change on this file since 3868 was 3858, checked in by ansari, 15 years ago

petit ajout ds sophya.tex (ConvertTostdvec()), Reza 12/08/2010

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